/** * * @author Maxim Gorshkov * @URL www.mgorshkov.com * Problem #37 Project Euler * Link to problem: http://projecteuler.net/problem=37 * * Problem: Terribly inefficient! But it works..... (Slow...like 4 minutes slow). */ import java.io.*; import java.util.*; public class thirtyseven { public static void main(String[] args){ int n = 23; int index = 0; int array[] = new int[11]; long start = System.currentTimeMillis(); //we know from the specification of the question //that we have at most 11, so we might as well loop until //that point is reached. while(index<11){ if((isPrime(n) == true) && (isPrimeRight(n) == true) && (isPrimeLeft(n) == true)){ String temp = Integer.toString(n); if(!temp.startsWith("1")){ array[index] = n; index++; } else{ n++; } } n++; } long end = System.currentTimeMillis(); long timeTaken = end - start; sumAndPrintArray(array); System.out.println("Solution took: "+timeTaken+"ms"); } //check to see if it is, in fact a prime number //by checking if it is divisible by numbers between 2 and itself-1 //if it is not, it must be prime... static boolean isPrime(int a){ for(int i = 2; i