← Unit 2 · all exercises
Saved in this browser only

Sum of squares

Return 1×1 + 2×2 + ... + n×n. For n = 3 that is 1 + 4 + 9 = 14.

int sumOfSquares(int n)

Solution.java
Loading editor…
Results

Examples

  • sumOfSquares(3) → 14
  • sumOfSquares(1) → 1

There are also 4 hidden tests you can't see. Solve the problem, not the examples.