Write a program called Lab6 that prompts the user to enter two integers; store t
ID: 3528451 • Letter: W
Question
Write a program called Lab6 that prompts the user to enter two integers; store these inputs in variables. Then compute the sum and product of the integers and display the results on the screen by calling two methods to complete these tasks. You must write and use two methods in your program: 1) computeSum is a void method that has two int parameters. This method calculates the sum of the two parameters and then displays the sum. 2) computeProduct is a void method that has two int parameters. This method calculates the product of the two parameters and then displays the product. So your program should get the input from the user, then call the computeSum method (passing the inputs as arguments), and then call the computeProduct method (again, passing the inputs as arguments).Explanation / Answer
Please rate with 5 stars :) import java.util.Scanner; class AddNumbers { void sum(int a,int b) { System.out.println("Sum of entered integers = "+(a+b)); } void prod(int a,int b) { System.out.println("Sum of entered integers = "+(a*b)); } public static void main(String args[]) { int x, y, z; System.out.println("Enter two integers to calculate their sum "); Scanner in = new Scanner(System.in); x = in.nextInt(); y = in.nextInt(); sum(x,y); prod(x,y); } }
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.