Ask Question

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

+4
Answers (1)
  1. 29 June, 02:21
    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?
Find 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 the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers