Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Test {
- public static boolean isPrime(int n) {
- for (int i = 2; i <= Math.sqrt(n); i++) // check possible factors
- {
- if (n % i == 0) { // i is a factor
- return false; // so n is not prime
- }
- }
- return true; // no factors so it is prime
- }
- public static void main(String[] args) {
- for (int i=2; i<100; i++) // test - all primes less than 100
- if (isPrime(i)) System.out.println(i);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment