I am submitting my code for Euler10 puzzle at Gild.com in Java using its online editor. The code runs perfectly for all test cases on my PC but compilation on Gild fails. I am following all of its coding rules but I think I'm still missing something.
Here's my code:
class Euler10 {
public static void main(String[] args) throws java.lang.Exception
{
java.io.BufferedReader br = new java.io.BufferedReader (new java.io.FileReader(args[0]));
int number = Integer.parseInt(br.readLine());
boolean[] isPrime = new boolean[number + 1];
for (int i = 2; i <= number; i++)
isPrime[i] = true;
for (int i = 2; i*i <= number; i++)
{
if (isPrime[i])
{
for (int j = i; i*j <= number; j++)
isPrime[i*j] = false;
}
}
long primesum = 0;
for (int i = 2; i < number; i++)
{
if (isPrime[i])
primesum = primesum+i;
}
System.out.println(""+primesum+"\n");
}
}
After compiling this code in debug mode, I get the following error:
My program output shown above is same as the test case output even though it gives wrong result.
Also tell me what is a Diff Output in this context.
(I want to submit the code in the online editor only.)
Gild coding Puzzle FAQs &
Submission guidelines
Thanks
It seems that the problem is that your output is not identical to the expected output. Try replacing your last line
System.out.println(""+primesum+"\n");
with(System.out.println(""+primesum);