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

Respuesta :

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.        
  7.        // Prompt user to input first number
  8.        System.out.print("Input first number: ");
  9.        double R = input.nextDouble();
  10.        // Prompt user to input first number
  11.        System.out.print("Input second number: ");
  12.        double T = input.nextDouble();
  13.        
  14.        // Display R and T  
  15.        System.out.println("R = " + R);
  16.        System.out.println("T = " + T);
  17.        // Display Sum of R and T
  18.        System.out.println("R + T = " + (R + T));
  19.        // Display Difference between R and T
  20.        System.out.println("R - T = " + (R - T));
  21.        // Display Product of R and T
  22.        System.out.println("R * T = " + (R * T));
  23.    }
  24. }

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).

ACCESS MORE