Monday, March 12, 2007

To find prime number


public class prime{
public static void main(String args[]){
for(int i = 0; i <= 100; i++){
if(isPrime(i))
System.out.println(i);
}
}

public static boolean isPrime(int checkNumber) {
double root = Math.sqrt(checkNumber);
for (int i = 2; i <= root; i++) {
if (checkNumber % i == 0)
return false;
}
return true;
}
}

1 comment:

Jerry said...
This comment has been removed by a blog administrator.