Code compilation fails on Gild in Java

126 Views Asked by At

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

2

There are 2 best solutions below

0
On BEST ANSWER

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);

0
On

Your program produces the wrong result, and (1) you don't tell us what it's supposed to do, nor do you (2) show us your program. Are we psychics here?

Anyway, the diff (short for difference) output is showing you that either there's a newline at the end of your output, and it's not supposed to be there, or possibly the other way around -- you'd have to read the "help reading diff output" link.)

Does that help?