Guest User

Untitled

a guest
Apr 24th, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.78 KB | None | 0 0
  1. public class CountPrime {
  2.  
  3. public static void main(String[] args) {
  4. int beginInterval = 0;
  5. int endInterval = 100;
  6. int numberOfPrimes = 0;
  7.  
  8. for(int i = beginInterval; i < endInterval; i++) {
  9. if(i == 2 || i == 3) {
  10. numberOfPrimes++;
  11. }
  12.  
  13. if(i % 2 == 0 || i % 3 == 0 || i == 1) {
  14. continue;
  15. }
  16.  
  17. int n = 5;
  18. boolean isPrime = true;
  19.  
  20. while(n*n <= i) {
  21. if(i % n == 0 || i % (n+2) == 0) {
  22. isPrime = false;
  23. break;
  24. }
  25. n += 6;
  26. }
  27.  
  28. if(isPrime) {
  29. numberOfPrimes++;
  30. }
  31. }
  32. System.out.println(numberOfPrimes);
  33. }
  34. }
Add Comment
Please, Sign In to add comment