public class Goldbach // use recursion to compute prime pairs that sum up to every even number from 6 to 9998 { public static void main(String[] args) { int i; boolean temp=true; for(i=6;i<10000;i+=2) // we will search from 6 to 9998 to see if Goldbach's theorem holds for these numbers { temp=find(3,i-3); // our prime numbers will all be odd, so we start at i=3 and see if i-3 is also prime, if not, we try the next pair at i+2 and i-3-2 if(!temp) System.out.println(i + " is not a Goldblatt number"); // if we find such a pair, output it } } public static boolean find(int x, int y) // x will start at 3 and increment by 2 each time, y will start at i-3 and decrement by 2 each time until we find two primes { if(x>y) return false; // if x > y we haven't found such a pair, we have proven Goldbach's theorem as false! else if(isprime(x,2)&&isprime(y,2)) // otherwise if x and y are both primes, output this pair and return true { System.out.println((x+y) + " = " + x + " + " + y); return true; } else return find(x+2,y-2); // otherwise recurse } public static boolean isprime(int x,int y) // recursive prime method - determine if x is prime starting with divisor y { if(y>x/2) return true; // if y > x/2 we have tested from 2..x/2 and haven't found a divisor and therefore these is none other than 1 and x, so x is prime else if(x%y==0) return false; // otherwise if y divides into x evenly, then y is a divisor and so x is not prime else return isprime(x,y+1); // otherwise continue to recurse trying y+1 as a divisor } }