public class Test2E extends Object
| Modifier and Type | Field and Description |
|---|---|
static int |
MAX_DIGITS
The maximum number of digits in a Java int.
|
| Modifier and Type | Method and Description |
|---|---|
static List<Integer> |
allGreaterThan(List<Integer> t,
int max)
Returns a new list containing all of the values in the given list
t greater than max. |
static double |
avg(int a,
int b,
int c)
Computes the average value of three numbers.
|
static void |
swap2(List<Integer> t)
Given a list containing exactly 2 integers, swaps the positions of the
integers in the list.
|
static int |
toInt(List<Integer> t)
Given a list
t whose elements are single digits, returns
the int value formed by joining the digits. |
public static final int MAX_DIGITS
public static double avg(int a,
int b,
int c)
a - a numberb - a numberc - a numberpublic static void swap2(List<Integer> t)
[-5, 9]
swap2 modifies the list so that it becomes
[9, -5]
t - a list containing exactly 2 integersIllegalArgumentException - if the list does not contain exactly 2 integerspublic static List<Integer> allGreaterThan(List<Integer> t, int max)
t greater than max. An empty list is returned
if no value in t is greater than max.
The list t is not changed by this method.
For example, if max == 5 then:
t Test2E.allGreaterThan(t, max) -------------------------------------------------- [] [] [4] [] [9] [9] [4, 5, 6, 7, 8] [6, 7, 8]
t - a list of valuesmax - all values in the returned list will be greater than
maxt that
are greater than maxpublic static int toInt(List<Integer> t)
t whose elements are single digits, returns
the int value formed by joining the digits.
The list t is not changed by this method.
For example, here are
some lists and their corresponding int values:
[] (the empty list) 0 [4] 4 [5, 2] 52 [8, 7, 3] 873 [-1, 0, 0, 0] -1000
If joining the digits of the list produces a positive value greater
than Integer.MAX_VALUE then Integer.MAX_VALUE
is returned.
If joining the digits of the list produces a negative value less
than Integer.MIN_VALUE then Integer.MIN_VALUE
is returned.
t - a list of digits