Write a Java program that simulates a calculator. It first displays a menu like the one given below:
Write a Java program that simulates a calculator. It first displays a menu like the one given
below:
Press + for addition
Press - for subtraction
Press * for multiplication
Press / for division
Press % for remainder
Press S or s for square root
Press P or p for power
The program takes the choice and stores it in a char type variable. Based on the choice,
prompt the user to enter two operands (two operands are required for all functions except square
root) and then display the result of calculations. The operands must be of type double.
Rules:
1. If the user enters a choice other than the available ones, your program should displayan
error message and stop.
2. For division, if the second operand is 0, display an error message “Division by Zero not
allowed”
3. For square root, the program should take only one input i.e. first operand.
Note : using Java Language
Trending now
This is a popular solution!
Step by step
Solved in 3 steps with 1 images