Advertisement
Guest User

Untitled

a guest
Jun 26th, 2017
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.98 KB | None | 0 0
  1. public static void main( String[] args )
  2. {
  3. int limit = 10;
  4. boolean[] primes = new boolean[( limit + 1 )];
  5. primes[0] = false;
  6. primes[1] = false;
  7. for ( int x = 2; x < ( limit + 1 ); x++ )
  8. {
  9. primes[x] = true;
  10. }
  11. long sum = 0;
  12. int x = 3;
  13.  
  14. for ( int index = 2; (index * index) <= limit; index++ )
  15. {
  16. x = index * index;
  17. while ( x < limit - index )
  18. {
  19. x = x + index;
  20. primes[x] = false;
  21. System.out.println( x + " is false" );
  22. }
  23. while ( !primes[index] )
  24. {
  25. index++;
  26. }
  27. }
  28.  
  29. for ( int index = 2; primes[index] == true && index <= limit; index++ )
  30. {
  31. sum = sum + index;
  32. System.out.println( "adding " + index );
  33. }
  34.  
  35. System.out.println( "The sum is " + sum );
  36.  
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement