/* Get n from the commandline argument and prints all primes <= n. * * This program demonstrates the use of nested for loops. */ class PrimesUsingFor { public static void main(String[] args) { int maxN = Integer.parseInt(args[0]); int count = 0; System.out.println("Prime Table\n==========="); for (int n = 2; n <= maxN; n++) { int d; for (d = 2; d < n; d++) { if (n % d == 0) break; } if (d == n) { System.out.printf("%5d", n); count++; if (count == 10) { System.out.println(); count = 0; } } } if (count < 10) System.out.println(); } }