Hello! its me again, I need a liitle help.
Our teacher gave us a homework where we need to create a program that will determine the larger of the two inputed number, plus we have to determine if the input is an integer or not. Ive already coded the program, but when I run it whenever I enter anything other than an integer it goes into an infinte loop (instead of asking for another input) HELP PLEASEEEE
import java.util.*;
public class Homework1b {
public static void main (String [] args)
{
Scanner input = new Scanner(System.in);
int number1=0,
number2=0;
boolean num1=false,
num2=false;
Compare check = new Compare();
while(num1==false){
System.out.print("Enter an Integer: ");
if (input.hasNextInt())
{
number1=input.nextInt();
num1=true;
}
else
System.out.println("Invalid Input!");
}
while(num2==false){
System.out.print("Enter another Integer: ");
if (input.hasNextInt())
{
number2=input.nextInt();
num2=true;
}
else
System.out.println("Invalid Input!");
}
check.compare(number1,number2);
}
}