All pastes #165581 Raw Edit

Unnamed

public text v1 · immutable
·published 2006-09-10 00:03 UTC
rendered paste body
static int[] a = new int[100];
	static int index = 3;
	static
	{
		a[0]=2;
		a[1]=3;
		a[2]=5;
		a[3]=7;
	}

	public int nextPrime()
	{
		//creat an arry.
		//divide the number with all the prime numbers you have so far. 
		//if none of them results in a reminder of zero,
		//then the number must be prime.
		//you add this new prime number to the collection of primes you have so far. 
		//then return the prime number
		int n = a[index] + 1;
		while(true)
		{
			for(int i=0; i<index ; i++)
			{
                            if (n % a[i]== 0) {
                              n++;
                              break;
                            }
			}
			
		}
	
	}