Chapter 20 (Christian web host) Java Utilities Package and Bit Manipulation

Chapter 20 Java Utilities Package and Bit Manipulation 1193 84 for ( int i = 2; i < size; i++ ) 85 86 if ( sieve.get( i ) ) { 87 primesArea.append( String.valueOf( i ) ); 88 primesArea.append( ++counter % 7 == 0 ? "n" : "t" ); 89 } 90 91 setSize( 600, 450 ); 92 setVisible( true ); 93 } 94 95 // execute application 96 public static void main( String args[] ) 97 { 98 BitSetTest application = new BitSetTest(); 99 100 application.setDefaultCloseOperation( 101 JFrame.EXIT_ON_CLOSE ); 102 } 103 104 } // end class BitSetTest Fig. 20.13 Fig. 20.13 Demonstrating the Sieve of Eratosthenes using a BitSet(part 3 of 3). Line 22 creates a BitSet of 1024 bits. We ignore the bit at index 0 in this program. Lines 68 69 set all the bits in the BitSetto on with BitSetmethod set. Lines 72 79 determine all the prime numbers from 2 to 1023. The integer finalBit specifies when the algorithm is complete. The basic algorithm is that a number is prime if it has no divisors other than 1 and itself. Starting with the number 2, once we know a number is prime, we can eliminate all multiples of that number. The number 2 is only divisible by 1 and itself, so it is prime. Therefore, we can eliminate 4, 6, 8 and so on. Elimination of a value consists
Note: In case you are looking for affordable webhost to host and run your servlet application check Vision make web site services

Leave a Reply