title: How to repeat something until correct input is given in java?
body: <p>I am trying to make a application and for one part of the application I need to get a input from the user stating how many times there click their mouse in 1 second. I want the input their give to be between 1-10 and any other number given e.g. 0, -1, 11 to provide them with a error and ask them to input a valid number of 1-10. Also if the user types in any character e.g. name, A, Jo or hello, to also provide them with a error and ask them to provide the correct input. Below is what I have but it does not work.</p>
  
  <pre><code>    int OrginalMouseClick;
  
      String Mouseclick = JOptionPane.showInputDialog("Write down how many times you can click your mouse button in 1 second");
      int Mouseclick2 = Integer.parseInt(Mouseclick);
  
      while (Mouseclick2 &lt; 1 || Mouseclick2 &gt; 10) {
          String Mouseclick = JOptionPane.showInputDialog("Write down how many times you can click your mouse button in 1 second");   
           if (Mouseclick2 &gt;= 1 || Mouseclick2 &lt;10) {
               OrginalMouseClick = Mouseclick2;
               }
           }
  </code></pre>
  
  <p>I haven't yet implemented not to accept any characters like name, j, A, hello because I am not sure how I can do this, can someone show me please. </p>
  
  <p>edit:
          int mouseClick;</p>
  
  <pre><code>    do {
          while (!str.hasNextInt()) {
              String str = JOptionPane.showInputDialog("Write down how many times you can click your mouse button in 1 second");
              str.next(); // this is important!
          }
          String str = JOptionPane.showInputDialog("Write down how many times you can click your mouse button in 1 second");
          mouseclick = Integer.parseInt(str);
      }
      while (mouseclick &lt; 1 || mouseclick &gt; 10);
  </code></pre>