I am trying to use Scanner object sc to read in an integer from user's input and need to assess whether it's greater than 0. So I set the following OR conditions in the while() to check whether it's an empty line or the input number is less than 0. But the program does not take inputs after it encountered an invalid input. Any help is appreciated.
Scanner sc = new Scanner(System.in);
while (!sc.hasNextInt() || sc.nextInt() <= 0)
{
System.out.println("Invalid input\n the number needs to be greater than 0");
sc.next();
}
int number = sc.nextInt();
whileloop is going to be consuming all of thosenextInts.