Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class primeGenerator {
- public int count;
- public static int total;
- public int nextPrime()
- {
- {
- while (!isPrime(count))
- {
- count = count + 1;
- }
- } return count;
- }
- public static boolean isPrime(int n)
- {
- if (n < 2) return false;
- if (n % 2 == 0)
- // n is an even, so return true iff n is exactly 2
- return (n == 2);
- for (int i=3; i*i<=n; i+=2)
- if (n % i == 0)
- // i divides evenly into n, so n is not prime
- return false;
- return true;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement