Using while loop as input validation [duplicate]

I’m trying to use while loop to ask the user to reenter if the input is not an integer

for eg. input being any float or string

      int input;

      Scanner scan = new Scanner (System.in);

      System.out.print ("Enter the number of miles: ");
      input = scan.nextInt();
      while (input == int)  // This is where the problem is
          {
          System.out.print("Invalid input. Please reenter: ");
          input = scan.nextInt();
          }

I can’t think of a way to do this. I’ve just been introduced to java

Leave a Comment