-3

So this is a pretty basic code:

public class Problem14 {
    public static void main(String[] args) {
        long sumOfSquares = 0;
        long squareOfSums = 0;

        for(int i = 0; i < 100; i++) {
            sumOfSquares += (i * i);
        }

        for(int i = 0; i < 100; i++)
            squareOfSums += i;
        }
        squareOfSums = squareOfSums * squareOfSums; 
        long diff = sumOfSquares - squareOfSums;
        System.out.println(diff);
    }
}

Problem14.java:13: error: <identifier> expected
        squareOfSums = squareOfSums * squareOfSums; 
                    ^
Problem14.java:15: error: <identifier> expected
        System.out.println(diff);
                          ^
Problem14.java:15: error: <identifier> expected
        System.out.println(diff);
                               ^
Problem14.java:17: error: class, interface, or enum expected
}
^
4 errors

I'm not sure why I'm getting these errors. It's a really basic code!

I can't debug, since I get the error that my code has no main!

user2027425
  • 389
  • 3
  • 5
  • 14

2 Answers2

4

You are missing an opening { after the second for loop:

for(int i = 0; i < 100; i++) {
// Here ---------------------^
    squareOfSums += i;
}

In general, when you see unexpected errors that make little sense, it usually mean a bracketing imbalance or a missing semicolon.

Sergey Kalinichenko
  • 714,442
  • 84
  • 1,110
  • 1,523
0

One way to debug this kind of compiler error is to comment out all the code inside your method. Then uncomment each line (or block as with a for loop or if statement) one at a time and compile until you get the error message. This will help narrow down where the problem is.

Code-Apprentice
  • 81,660
  • 23
  • 145
  • 268