Skip to Main Content

New to Java

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

missing statement return & unreachable statement

807599Nov 14 2006 — edited Nov 15 2006
hi all. i need some help on some code i have to write for an assignement:
the pairPQ function generates 2 primal numbers between 19300 and 20250.
the isPrime function checks wether the generated numbers are prime or not

the problem is that i get "unreachable statement" and "missing return statement" errors when compiling. i know i have to return some values but i dont know where to place the return statement...
if anyone could help...
long pairPQ() //genere la paire de nombres p,q
  {
    while((isPrime(p) == false) && (isPrime(q) == false))
    {
      p = (int)(Math.random()*1000000);
      q = (int)(Math.random()*1000000);
      
      if (((19300 < p) && (p < 20250)) && ((19300 < q) && (q < 20250)) && (p != q))
      {
        return p;
        return q;
      }
    }
  }
boolean isPrime(int test) //verifie la primalite du nombre passe en argument
  {
    for( int a = 2 ; a < Math.sqrt(test) ; a++)
    {
      if (test % a != 0)
      {
        return true;
      }
    }
  }
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Dec 13 2006
Added on Nov 14 2006
22 comments
302 views