/* * This program demonstrates the use of nested while loops and break. */ class Primes { /* * This program prints all primes <= n where n is the number entered by * the user as a command line argument. */ public static void main(String[] args) { int limit = Integer.parseInt(args[0]); int n = 2; while (n <= limit) { boolean isPrime = true; int d = 2; while (d <= n-1) { if (n % d == 0) { isPrime = false; break; } d++; } if (isPrime) System.out.println(n); n++; } } }