Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int limit = 10;
- boolean[] primes = new boolean[100000];
- primes[0] = false;
- primes[1] = false;
- for ( int x = 2; x < ( limit + 1 ); x++ )
- {
- primes[x] = true;
- }
- long sum = 0;
- int x = 3;
- for ( int index = 2; index < ( Math.sqrt( limit ) + 1 )
- && primes[index] == true; index++ )
- {
- while ( x <= limit )
- {
- if ( x % index == 0 )
- {
- primes[x] = false;
- System.out.println( x + " is false" );
- }
- x++;
- }
- }
- for ( int index = 2; primes[index] == true && index <= limit; index++ )
- {
- sum = sum + index;
- System.out.println( "adding " + index );
- }
- System.out.println( "The sum is " + sum );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement