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
Post a Comment