UNB/ CS/ David Bremner/ teaching/ java/ GoodPrime.java
public class GoodPrime
{  /**
      Tests whether an integer is a prime
      @param n any positive integer
      @return true iff n is a prime
   */
   
   public static boolean isprime(int n)
   {  if (n == 1) return false;
      if (n == 2) return true;
      if (n % 2 == 0) return false;
      int k = 3;
      while (k * k <= n)
      {  if (n % k == 0) return false;
         k = k + 2;
      }
      return true;
   }
   
   public static void main(String[] args)
   {  ConsoleReader console                       
         = new ConsoleReader(System.in);          
      System.out.print                            
         ("Please enter the upper bound: ");      
      int n = console.readInt();                  

      if (n >= 2) System.out.println(2);
      for (int i = 1; i <= n; i = i + 2)
      {  if (isprime(i))
            System.out.println(i);
      }
   }
}