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?
public  static int nextPrime(int input) {
    input++;
    //now find if the number is prime or not
    for(int i=2;i<input;i++) {
        if(input % i ==0  ) {
            input++;
            i=2;
        }
        else{
            continue;
        }
    }
    return input;
}
 
     
     
     
     
     
     
     
     
     
     
     
     
     
     
    