public static void main(String[] args){
char OperatorCode;
int answer;
int firstOperand;
int secondOperand;
String inputString;
boolean quit = false;
Scanner inLine = new Scanner(System.in);
do{
System.out.print("Enter the Operator Code (A,S,M or D): ");
inputString = inLine.nextLine();
OperatorCode = inputString.charAt(0);
if (OperatorCode != 'Q'){
inputString = inputString.substring(1, inputString.length());
Scanner string = new Scanner(inputString);
System.out.print("Enter the First Operand: ");
firstOperand = string.nextInt();
System.out.print("Enter the Second Operand: ");
secondOperand = string.nextInt();
switch (OperatorCode){
case 'A' : answer = (firstOperand + secondOperand);
System.out.println(firstOperand + " + " + secondOperand + " is " + answer);
case 'S' : answer = (firstOperand - secondOperand);
System.out.println(firstOperand + " - " + secondOperand + " is " + answer);
case 'M' : answer = (firstOperand * secondOperand);
System.out.println(firstOperand + " * " + secondOperand + " is " + answer);
case 'D' : answer = (firstOperand / secondOperand);
System.out.println(firstOperand + " / " + secondOperand + " is " + answer);
break;
}
} else
quit = true;
}while (!quit);
}
}
What seems to be the problem on my code? It outputs the first statement(?) fine and I can input my desired character there but when it goes to the second statement(?) ("Enter the first Operand.") I get an error which says"
"Enter the First Operand: Exception in thread "main" java.util.NoSuchElementException"
Can somebody please point out my fault?