Advertisement
Guest User

Untitled

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