Advertisement
Guest User

Untitled

a guest
Oct 30th, 2014
195
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.56 KB | None | 0 0
  1.  
  2. public class primeGenerator {
  3.  
  4. public int count;
  5. public static int total;
  6.  
  7. public int nextPrime()
  8. {
  9. {
  10. while (!isPrime(count))
  11. {
  12. count = count + 1;
  13. }
  14. } return count;
  15. }
  16.  
  17. public static boolean isPrime(int n)
  18. {
  19. if (n < 2) return false;
  20. if (n % 2 == 0)
  21. // n is an even, so return true iff n is exactly 2
  22. return (n == 2);
  23. for (int i=3; i*i<=n; i+=2)
  24. if (n % i == 0)
  25. // i divides evenly into n, so n is not prime
  26. return false;
  27. return true;
  28. }
  29.  
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement