The call of scanner.nextInt() advances the position at which the scanner reads its input, so the second read may produce a different number, or throw an exception when there is only one int available. To work around this situation you could introduce a variable to hold the value for the second check:
int tmp;
while (scaner.hasNextInt() && (tmp = scaner.nextInt()) > 0 && tmp < 10) {
...
}
The second subexpression (tmp = scaner.nextInt()) reads the next integer value from the scanner, and stores it in a temporary variable tmp. After that, the value is compared with zero, and finally the same value is compared to 10.
The assignment is performed before the check of tmp < 10 because parts of && expressions are processed in left to right order.
This solution is not ideal, because tmp remains visible after the loop, and because it is not so easy to read. You would be better off moving the check inside the loop, like this:
while (scaner.hasNextInt()) {
int val = scaner.nextInt();
if (val < 0 || val >= 10) {
break;
}
...
}
My idea was the code to keep prompting you for new input until its correct
A common way to achieve this is with a do/while loop:
int val = -1;
do {
System.out.print("Enter an int: ");
if (scanner.hasNextInt()) {
val = scanner.nextInt();
} else {
scanner.nextLine();
}
} while (val < 0 || val >= 10);