Write a Java Program that adds 2 numbers using a return type method & passing ar
ID: 3759602 • Letter: W
Question
Write a Java Program that adds 2 numbers using a return type method & passing arguments
public class AddNumbers {
main method() {
//declare local variables for 2 numbers
// request user input for the two number and change the console input to the appropriate data type
// call the method showSum(value1, value2)
} // end main()
//The showSum method displays the sum of two numbers.
public static void showSum(double num1, double num2) {
// put in appropriate code to calculate the sum
// put in appropriate code to return the sum
} // end showSum
}//end of AddNumbers
Explanation / Answer
public class AddNumbers {
public static void main(String[] args) {
double value1;
double value2;
// request user input for the two number and change the console input to the appropriate data type
Scanner s=new Scanner(System.in) ;
value1=s.nextDouble();
value2=s.nextDouble();
// call the method
System.out.println(showSum(value1, value2) );
} // end main()
//The showSum method displays the sum of two numbers.
public static void showSum(double num1, double num2) {
// put in appropriate code to calculate the sum
double sum=num1+num2;
// put in appropriate code to return the sum
return sum;
} // end showSum
}//end of AddNumbers