public final class RangeSum extends Object
| Modifier and Type | Method and Description |
|---|---|
static long |
sumOfRange(long end)
Calculate the sum of all values from 1 to
end, including. |
static long |
sumOfRange(long start,
long end)
Calculates the sum of all values from
start to end, including. |
public static long sumOfRange(long end)
end, including. That is:
sum = 1 + 2 + 3 + ... + (end-1) + end
f(0) = 0
f(1) = 1
f(2) = 3
f(3) = 6
f(10) = 55
f(100) = 5050
end - The end value of the sum-range.end, including.public static long sumOfRange(long start,
long end)
start to end, including.start - The start value of the sum-range.end - The end value of the sum-range.start to end , including.Copyright © 2012. All Rights Reserved.