title: How to restrict the user to enter number between certain range in java?
body: <p>In Java, if you want to ask users, for example, to input numbers only between 1,000 and 100,000, the program would continue further. Otherwise, ask the user to input the number again in the given range. </p>
  
  <p>Edit: Here, my program only tries to validate the input only once. How shall I make to ask the user to input until valid data(i.e between 1000-100000) is entered </p>
  
  <pre><code>public static void main(String args[]) {
  
      Scanner sc = new Scanner(System.in);    
      System.out.print("Principal:");
      double principal = sc.nextDouble();
  
      if(principal&lt;1000 || principal &gt;100000) {
          System.out.println("enter principal again:");
          principal = sc.nextDouble();        
      }
  }
  </code></pre>