Saturday, September 5, 2020

To write a java program to find the sum for the given variables using method with default arguments.

import java.util.Scanner;
 public class Method
 {
   private static Scanner sayed;
  public static void main(String[] args)
   {
    int a,b,c;
    
    sayed=new Scanner (System.in);
    System.out.println("Enter a:");
    a=sayed.nextInt();
    System.out.println("Enter b:");
    b=sayed.nextInt();
    System.out.println("Enter c:");
    c=sayed.nextInt();
    
    System.out.println(sum (a,b,c));
    }
    public static double sum (int a, int b, int c)
    { 
      System.out.println("\nThe sum of a+b+c:");
      return a+b+c;
    }
   } 

No comments:

Post a Comment