title: How to make the program ask the user for input until they give a valid response?
body: <p>could you please help me to make this program to get a correct number? The program should check the input type, it should be int. Also, the program should check that the value is from 1 to 10. If these conditions are true, the value should be assigned to correctNumber. So far I came up to this piece of code but I have difficulties in making it work properly.</p>
  <pre><code>System.out.println(&quot;Enter a number from 1 to 10:&quot;);
      Scanner scanner = new Scanner(System.in);
      while (!scanner.hasNextInt() || !isCorrectNumber(scanner.nextInt())) {
                  System.out.println(&quot;Incorrect input!&quot;);
                  scanner.next();
              }
              int correctNumber = scanner.nextInt();
      
          }
      private static boolean isCorrectNumber(int n) {
          return size &gt;= 1 &amp;&amp; size &lt;= 10;
      }
  </code></pre>