Posted By


gdonald on 09/27/06

Tagged


Statistics


Viewed 853 times
Favorited by 1 user(s)

Java prime number generator


/ Published in: Java
Save to your folder(s)



Copy this code and paste it in your HTML
  1. package com.destiney.Prime;
  2. class Prime
  3. {
  4. public static void main( String args[] )
  5. {
  6. int x, y, c = 0;
  7. for( x = 2; x < 1000; x++ )
  8. {
  9. if( x % 2 != 0 || x == 2 )
  10. {
  11. for( y = 2; y <= x / 2; y++ )
  12. {
  13. if( x % y == 0 )
  14. {
  15. break;
  16. }
  17. }
  18.  
  19. if( y > x / 2 )
  20. {
  21. System.out.println( x );
  22. c++;
  23. }
  24. }
  25. }
  26. System.out.println( "\nTotal: " + c );
  27. }
  28. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.