Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //PrimeGen.java MrG 2012.0113
- public class PrimeGen
- {
- private int current;
- public PrimeGen()
- {
- current = 1;
- }
- public int nextPrime()
- {
- do
- {
- current++;
- }
- while(!isPrime());
- return current;
- }
- private boolean isPrime()
- {
- if(current<2){return false;}
- if(current==2){return true;}
- if(current%2==0){return false;}
- for(int i=3; i*i<=current; i+=2)
- {
- if(current%i==0){return false;}
- }
- return true;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement