Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package loopUnroll;
- class isPrime {
- static boolean isPrime(int n, int i) //taken from geeksforgeeks
- {
- if (n <= 2)
- return (n == 2) ? true : false;
- if (n % i == 0)
- return false;
- if (i * i > n)
- return true;
- // Check for next divisor
- return isPrime(n, i + 1);
- }
- }
- public class LoopClass
- {
- private int n; //how many primes
- isPrime x = new isPrime();
- public LoopClass(int n)
- {
- this.n = n;
- }
- public void Roll()
- {
- //for(int i = 0; i < this.n; i++) //go until workload
- int i = 0;
- while(true)
- {
- try
- {
- if(isPrime.isPrime(i, 2))
- {
- //System.out.println(i);
- i++;
- continue;
- }
- }
- catch(Exception e)
- {
- System.out.println(e);
- System.out.println("Reached " + i);
- }
- }
- }
- public void Unroll(int L)
- {
- //for(int i = 0; i < this.n; i++) //go until workload
- int i = 0;
- while(true)
- {
- int j = 0;
- try
- {
- do
- {
- if(isPrime.isPrime(i, 2)) //should do this L times per unroll?
- {
- i++;
- continue;
- }
- j++;
- }while(j < L);
- }
- catch(Exception e)
- {
- System.out.println(e);
- System.out.println("Reached " + i);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement