title: How to limit the user to enter 4 digit pin in java
body: <p>I want to take input of pin from the user and I want to limit the user to take 4 digit pin. I tried with [But when I enter 0001 it's not working it again ask to enter 4 digit pin then please solve it</p>
  <pre><code>void pin1()
  {
      //int pin;
      for(int i=1;i&lt;=1000;i++)
      {
          try
          {
                  pin=obj.nextInt();
                  if(pin&lt;=9999 &amp;&amp; pin&gt;=1000)
                  {
                  }
                  else
                  {
                      System.out.println(&quot;Pin must be four digit&quot;);
                      pin1();
                  }
  
              break;
          }
          catch(InputMismatchException e)
          {
              obj.next();
              System.out.println(&quot;Error use numbers not alphabets or characters&quot;);
          }
      }
  }
  </code></pre>