java - Some of my prime numbers are coming up as not prime -


this question exact duplicate of:

im not sure whats wrong code, seems things coming prime.

public static char isprime(int x)         {             char result = 'r';             for(int y=2;y<x;y++)             {                 if(x%y==0)                 result = 't';                 else                 result = 'f';             }             return result;         } 

you going end of loop result x-1.

you need start result = 't' , break out of loop false values.


Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -