Problem: Sum of Squares
Problem Statement
The sum of squares is the sum of a sequence of numbers
up to a specified integer. For example, the sum of squares from 1 to 5
should be 55 because
12 + 22 + 32 + 42 + 52 = 55.
Given start and end values as integers, write a function that returns the sum of squares.
Definition
- Class: SumUp
- Function/Method: sumSquares
- Parameters: int, int
- Returns: int
- Method signature (see below)
public int sumSquares(int low, int high)
Class
public class SumUp
{
public int sumSquares(int low, int high)
{
// TODO: fill in sumSquares
}
}
Constraints
-
low ≤ high
- The sum of squares will be
less than
Integer.MAX_VALUE, so you do not need to
worry about integer overflow.
Hint
- There is a formula for the sum of squares. Using that will certainly
make this calculation easier.
Examples
1 1
Returns: 1
-5 0
Returns: 55
Comments?