/** class Primes generates a table of primes. */ public class Primes { /** read in an integer max from the command line and print out a table of primes <= max */ public static void main(String[] args) { int max = Integer.parseInt(args[0]); System.out.println("Table of Primes <= " + max); int count = 0; for (int n = 2; n < max; n++) { if (isPrime(n)) { System.out.print(n + " "); count++; if (count % 10 == 0) System.out.println(); } } System.out.println(); } /** return true if n is a prime, return false otherwise. */ public static boolean isPrime(int n) { if (n == 2) return true; int d = 2; while (d < n) { if (n % d == 0) return false; else d++; } return true; } }