title: Optimal way to find next prime number (Java)
body: <p>I was asked to write a program to find next prime number in an optimal way. I wrote this code, but I could not find an optimal answer to it. Any suggestions?</p>
  
  <pre><code>public  static int nextPrime(int input) {
  
      input++;
      //now find if the number is prime or not
  
      for(int i=2;i&lt;input;i++) {
          if(input % i ==0  ) {
              input++;
              i=2;
          }
          else{
              continue;
          }
      }
      return input;
  }
  </code></pre>