Implement the method sumOfSquares that returns the sum of squares from 1 to n.
Return the sum 1^2 + 2^2 + ... + n^2. For example, when n = 3, the result is 14.
The task is designed to test careful handling of edge cases, not only the most common input.
- Return
0whennis0. - Inputs are non-negative.
- A loop or the mathematical formula may be used.
Add i * i for every number from 1 through n, or apply the known sum-of-squares formula.