1   // joi/examples/PrimesDemo.java                         
2   //                                                            
3   //                                                            
4   // Copyright 1998-2001 Bill Campbell and Ethan Bolker                         
5                                                               
6   // %> java PrimesDemo
7   // 91      false
8   // 101     true
9   
10  public class PrimesDemo 
11  {
12      public static boolean test( int n ) 
13      {
14          if ( n < 0 ) n = -n;
15          if ((n == 1) || (n == 0)) return false;
16          if (n == 2) return true;
17          if (n % 2 == 0 ) return false;
18          double limit = Math.sqrt(n);
19          for (int j = 3; j <= limit; j += 2) {
20              if (n % j == 0) return false;
21          }
22          return true;
23      }
24  
25      public static void main( String[] args ) 
26      {
27          System.out.println(91 +  "\t" + PrimesDemo.test(91));
28          System.out.println(101 + "\t" + PrimesDemo.test(101));
29      }
30  }
31