public class PrimeNumbers {
public static void main(String args[]) {
for(int x = 1; x < 50; x++) {
if(isPrime(x)){
System.out.println(x);
}
}
}
public static boolean isPrime(int x) {
if (x < 2)
return false;
for(int i=2; i<x; i++) {
if(x % i == 0) {
return false;
}
}
return true;
}
}
Output:
$ java PrimeNumbers 2 3 5 7 11 13 17 19 23 29 31 37 41 43 47