FOR LOOP DEAD CODE IN JAVA

Takeshi Okada

Total Post:89

Points:629
Posted by  Takeshi Okada
Java 
 876  View(s)
Ratings:
Rate this:
I'm getting a dead code warning in a for loop at i++. Why do I get that, and how do I solve this problem?

public static boolean Method(int p) {
    for(int i = 2; i < p; i++) {  // here is the problem, at i++
        if(p % i == 0);         
            return false;
    }
    return true;    
}
  1. Mayank Tripathi

    Post:397

    Points:3117
    Re: for loop dead code in java

    Problem is in this line:

    if(p % i == 0); 
    Remove semicolon and try again

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!