I am clueless about how to change this into arithmetic expressions.
It is supposed to do the same thing but instead of using 3 inputs from the user it is supposed to be 1 input.
The readDouble();
and readChar();
are premade scanner methods that are imported from a package. Help is needed.
import static dit948.SimpleIO.*;
public class Exce1 {
public static void main(String[] args) {
double n1, n2;
char operation;
println("Enter the first number: ");
n1 = readDouble();
if(n1 == 0){
println("The program is terminated. Bye");
System.exit(0);
}
println("Enter the operator: ");
operation = readChar();
println("Enter the second number: ");
n2 = readDouble();
switch(operation){
case '+':
println("The result is " + (n1 + n2));
break;
case '-':
println("The result is " + (n1 - n2));
break;
case '*':
println("The result is " + (n1 * n2));
break;
case '/':
println("The result is " + (n1 / n2));
break;
}
}
}