Q:

How can I check if numbers are consecutive primes?

The input line contains three positive integers: r, s, and a, where (2 <= r < s < a).  It is guaranteed that r is prime.
It should print YES, if s is the next prime number after r and a is the next prime number after s; otherwise, it should print NO.
Currently, I have the following isPrime() method:
boolean isPrime(int n)  {
    //check if n is a multiple of 2
    if (n%2==0) 
        return false;
    //if not, then just check the odds
    for(int i=3;i*i<=n;i+=2) {
        if(n%i==0)
            return false;
    }
    return true; 
}

A:

Try this:
public int nextPrime(int start){
    int next = start+1;

    while(!isPrime(next)){
        next++;
    }

    return next;
}

public void arePrimeSequence(int r, int s, int a){
    int firstPrime = nextPrime(r);
    int secondPrime = nextPrime(firstPrime);

    if(s == firstPrime && a == secondPrime){
        System.out.println("YES");
    }
    else{
        System.out.println("NO");
    }
}

