Ask Question
Today, 01:49

Develop a menu-driven program that inputs two numbers and, at the user's option, finds their sum, difference, product, or quotient.

+3
Answers (1)
  1. Today, 05:01
    0
    import java. util. Scanner;

    public class TestClock {

    public static void main (String[] args) {

    Scanner in = new Scanner (System. in);

    System. out. println ("Enter num 1");

    double num1 = in. nextDouble ();

    System. out. println ("Enter num 2");

    double num2 = in. nextDouble ();

    System. out. println ("enter / "s/" for addition/t / "d/" for difference/t / "p/" for the product/t and / "q/" for the quotient");

    char op = in. next (). charAt (0);

    if (op = ='s'||op=='S') {

    double sum = num1+num2;

    System. out. println ("The sum is "+sum);

    }

    else if (op = ='d'||op=='D') {

    double diff = num1-num2;

    System. out. println ("The difference is "+diff);

    }

    else if (op = ='p'||op=='P') {

    double prod = num1*num2;

    System. out. println ("The product is "+prod);

    }

    else if (op = ='q'||op=='Q') {

    double quo = num1/num2;

    System. out. println ("The Quotient is "+quo);

    }

    }

    }

    Explanation:

    Use Scanner class to receive the two numbers and save in a two variables Create a new variable for Operation (op) to store a character Request the user to enter a character for the opearation (e. g s=sum, p=product, q=quotient and d=difference) Use if/else ... if statements to implement the required operation
Know the Answer?
Not Sure About the Answer?
Get an answer to your question ✅ “Develop a menu-driven program that inputs two numbers and, at the user's option, finds their sum, difference, product, or quotient. ...” in 📙 Computers & Technology if there is no answer or all answers are wrong, use a search bar and try to find the answer among similar questions.
Search for Other Answers