public class Utility2P extends Object
Modifier and Type | Field and Description |
---|---|
static String |
TEST_VERSION
The string describing this test version.
|
Modifier and Type | Method and Description |
---|---|
static String |
hello(String name)
Returns the string "Hello, " followed by the given name.
|
static List<Character> |
shuffle(List<Character> t)
Returns a new list of characters formed by shuffling the
characters of the given list.
|
static String |
toString(List<Character> t)
Returns the string formed by concatenating the characters
contained in the given list.
|
public static final String TEST_VERSION
public static String hello(String name)
Utility2P.hello("Tanya Tagaq");
returns the string:
"Hello, Tanya Tagaq"
name
- a non-null stringpublic static String toString(List<Character> t)
For example, if t was the list:
['g', 'o', 'o', 'd', 'b', 'y', 'e']
Then Test2P.toString(t) would return the string:
"goodbye"
t
- a non-null list of charactersIllegalArgumentException
- if the list t is emptypublic static List<Character> shuffle(List<Character> t)
To shuffle the characters in t, imagine splitting the list t in half so that the first (n / 2) characters of t are in one sublist, and the remaining (n / 2) characters of t are in the second sublist. The new returned list is formed by adding the first character of the first sublist to the new list, then adding the first character of the second sublist, then adding the second character of the first sublist, then adding the second character of the second sublist, and so on, until all of the characters in the two sublists are added to the new list.
For example, if t was the list:
['a', 'b', 'c', 'd', 'e', 'f']
then splitting t into two sublists yields:
['a', 'b', 'c'] and ['d', 'e', 'f']
Take the first two characters of each sublist and add them to the new list:
['a', 'd']
Then take the next two characters of each sublist and add them to the new list:
['a', 'd', 'b', 'e']
Then take the next two characters of each sublist and add them to the new list:
['a', 'd', 'b', 'e', 'c', 'f']
t
- a non-null list of characters