I'm new in java. I'm learning Java with book by Herbert Schildt. I want to write program that ask user to enter two variables, then ask to choose arithmetic operation and then program do this operation (like any calculator). I use this method - System.in.read
from Schildts book, but my program only can ask user to input one variable. Programs doesn't ask user to input second variable. How can I do this?
My code below:
class Calc {
public static void main(String args[])
throws java.io.IOException {
int a, b, result;
System.out.print("Enter first digit ");
a = (int) System.in.read();
System.out.println("Enter second digit ");
b = (int) System.in.read();
System.out.println("Choose operation");
System.out.println("Multiplication - 1 or Division - 2 ");
//int r;
result = (int) System.in.read();
switch(result) {
case 1:
System.out.println(a * b);
break;
case 2:
System.out.println(a / b);
break;
default: System.out.println("incorrect digit");
}
}
}