The overall homework assignment is not difficult, but I am having a bit of trouble figuring out how to use the CTRL-D in my program. The program records the amount of times a positive and negative integer is typed. When the user decides to end the program, they will use the CTRL-D to terminate the program. After the button combination has been pressed, I spit out to the user the results. The problem is when I press CTRL-D the program just terminates and I can't even get it to read the next line of code. Any help that can possibly point me in the right direction will be greatly appreciated.
--- Update ---
If Control D is pressed, it does print out the CTRL-Z, which is progress. The problem is if the user enters a numerical value and presses CTRL -D it does print out "CTRL-Z". I am clearly missing something hear. Is there a way to have the user entering numbers in, and once he presses CTRL-Z it can either say "CTRL-Z" or get out of the while loop and print out "Test".PHP Code:
public static void main(String[] args) {
// number entered and the running total
int inputNum, sum = 0;
// count of valid and invalid numbers seen
int numValid = 0, numInvalid = 0;
double average;
Scanner sr = new Scanner(System.in);
while (sr.hasNextLine()) {
System.out.println("CTRL-Z");
int inputNumber = sr.nextInt();
System.out.println(inputNumber);
}
System.out.println("Test");
}
}