135k views
3 votes
Design and implement a programming (name it SimpleMath) that reads two floating-point numbers (say R and T) and prints out their values, sum, difference, and product on separate lines with proper labels. Comment your code properly and format the outputs following these sample runs.Sample run 1:R = 4.0T = 20.0R + T = 24.0R - T = -16.0R * T = 80.0Sample run 2:R = 20.0T = 10.0R + T = 30.0R - T = 10.0R * T = 200.0Sample run 3:R = -20.0T = -10.0R + T = -30.0R - T = -10.0R * T = 200.0

1 Answer

7 votes

Answer:

  1. import java.util.Scanner;
  2. public class Main {
  3. public static void main(String[] args) {
  4. // Create a Scanner object to get user input
  5. Scanner input = new Scanner(System.in);
  6. // Prompt user to input first number
  7. System.out.print("Input first number: ");
  8. double R = input.nextDouble();
  9. // Prompt user to input first number
  10. System.out.print("Input second number: ");
  11. double T = input.nextDouble();
  12. // Display R and T
  13. System.out.println("R = " + R);
  14. System.out.println("T = " + T);
  15. // Display Sum of R and T
  16. System.out.println("R + T = " + (R + T));
  17. // Display Difference between R and T
  18. System.out.println("R - T = " + (R - T));
  19. // Display Product of R and T
  20. System.out.println("R * T = " + (R * T));
  21. }
  22. }

Step-by-step explanation:

The solution code is written in Java.

Firstly, create a Scanner object to get user input (Line 7). Next we use nextDouble method from Scanner object to get user first and second floating-point number (Line 9-15).

Next, display R and T and result of their summation, difference and product (Line 18-28).

User Steven Lacks
by
5.0k points