public class FlowChart
{
	public static void main(String [] args)
	{
		FlowChart run = new FlowChart();
		run.loop();
	}
	
	public void loop ( )
	{
		System.out.println("\n\n\n");
		int s = 12;
		int p = 15;
		do
		{
			System.out.printf("%4d%4d%n",s,p);
			if(p % 2 == 0)
			{
				p++;
			}
			if(isPrime(p))
			{
				if(p < s)
				{
					s = s - p;
					p += 2;
				}
				else
				{
					s--;
					if(s != 0)
					{
						p += 2;
					}
				}
			}
			else
			{
				p += 2;
			}
		}
		while(s != 0);
		System.out.printf("%4d%4d%n",s,p);
		System.out.println("\n\n\n");
	}
	
	public boolean isPrime(int number)
	{
		if(number < 2)
		{
			return false;
		}
		if(number == 2)
		{
			return true;
		}
		for(int i = 2; i < number; i++)
		{
			if(number % i == 0)
			{
				return false;
			}
		}
		return true;
	}
}

Back to APCS Main Page