Below is a section of my Reverse Polish Calculator.
If an integer is entered, push it to the stack and, if = is pressed, peek the result. However, I want to add another condition: if CTRL + D is pressed by the user, the program exits.
I've had a look online but can't seem to find any solutions. Any ideas? Thanks.
Scanner mySc = new Scanner(System.in);
//If input is an integer, push onto stack.
if (mySc.hasNextInt()) {
myStack.push(mySc.nextInt());
}
//Else if the input is an operator or an undefined input.
else if (mySc.hasNext()) {
//Convert input into a string.
String input = mySc.nextLine();
//Read in the char at the start of the string to operator.
char operator = input.charAt(0);
if (operator == '=') {
//Display result if the user has entered =.
}
**else if ("CTRL-D entered") {
System.exit(0);
}**