Tuesday, June 3, 2008

FInd Prime number in java

class FindPrime {
public static void main(String args[]) {
int num;
boolean isPrime = true;
num = 14;
for(int i=2; i <= num/2; i++) {
if((num % i) == 0) {
isPrime = false;
break;
}
}
if(isPrime) System.out.println("Prime");
else System.out.println("Not Prime");
}
}

1 comment:

windows error 1058 said...

hI,

i got it.. it worked for me.. thnaks for sharing this code.. it solved my problem..