Guest User

Untitled

a guest
Oct 19th, 2018
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.52 KB | None | 0 0
  1. public class PrimeNumbers {
  2.  
  3. public static void main(String[] args) {
  4. int top = 100;
  5. for (int i=2;i<top;i++){
  6. if(checkSimple(i))
  7. System.out.println(i);
  8. }
  9. }
  10.  
  11. public static boolean checkSimple(int i){
  12. if (i<=1)
  13. return false;
  14. else if (i <=3)
  15. return true;
  16. else if ((i%2==0) | (i %3 ==0))
  17. return false;
  18. int n = 5;
  19. while (n*n <=i){
  20. if (i % n ==0 | i % (n+2) == 0)
  21. return false;
  22. n=n+6;
  23. }
  24. return true;
  25. }
  26. }
Add Comment
Please, Sign In to add comment