public class Utility2A extends Object
Modifier and Type | Method and Description |
---|---|
static int |
alternatingSum(List<Integer> t)
Computes the alternating sum of the integers in the argument
list.
|
static Integer |
last(List<Integer> t)
Returns the last integer in the argument list.
|
static int |
totalArea(List<Integer> widths,
List<Integer> heights)
Computes the sum of the areas of zero or more rectangles.
|
public static Integer last(List<Integer> t)
t
- a list of integerspublic static int totalArea(List<Integer> widths, List<Integer> heights)
widths [1, 5, 10] heights [2, 3, 4]
The sum of the areas is equal to (1 * 2 + 5 * 3 + 10 * 4)
.
If a width or height of a rectangle is less than zero then
that area is not included in the sum.
widths
- a non-null list of rectangle widthsheights
- a non-null list of rectangle heightsIllegalArgumentException
- if widths and heights are lists
of different sizespublic static int alternatingSum(List<Integer> t)
[0, 1, 2, 3, 4, 5]
The alternating sum is given by (0 - 1 + 2 - 3 + 4 - 5). The alternating sum for an empty list is zero.
t
- a non-null list of integers