title: How to check if user input is not an int value
body: <p>I need to check if a user input value is not an int value. I've tried different combinations of what I know but I either get nothing or random errors</p>
  
  <p>For example:</p>
  
  <p>If the user inputs "adfadf 1324" it'll raise a warning message.</p>
  
  <hr>
  
  <p>What I have:</p>
  
  <pre><code>       // Initialize a Scanner to read input from the command line
         Scanner sc = new Scanner(System.in);
         int integer, smallest = 0, input;
         boolean error = false;
  
         System.out.print("Enter an integer between 1-100: ");
         range = sc.nextInt();
  
         if(!sc.hasNextInt()) {
  
            error = true;
            System.out.println("Invalid input!");
            System.out.print("How many integers shall we compare? (Enter an integer between 1-100: ");
            sc.next();
      }
  
         while(error) {
            for(int ii = 1; ii &lt;= integer; ii++) {
  
                ...
  
            } // end for loop
        }
        System.out.println("The smallest number entered was: " + smallest);
  
        }
    }
  </code></pre>