Question: Write a java program that prompts the user to enter two numbers a and b and an arithmetic operator op where op can be *

Write a java program that prompts the user to enter two numbers a and b and an arithmetic operator op where op can be * or /. The program then computes the result of a op b. The program should take into account the following cases: If the user enters an invalid operator, the program displays the error message Invalid operator!. If the user enters the division operator / and the denominator b is 0, the program displays the error message Division by 0 is not allowed!. Sample run 1: Enter two numbers: 15 2 Enter one of the operators (*, /): / 15.0 / 2.0 = 7.5 Sample run 2: Enter two numbers: 12 8 Enter one of the operators (*, /): + Invalid operator! Sample run 3: Enter two numbers: 7 0 Enter one of the operators (*, /): / Division by 0 is not allowed!

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!