public class Practice1A 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> |
repeatedChars(String s)
Returns a list of the characters that appear more than once in the string s.
|
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)
Practice1A.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 Practice1A.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 characterspublic static List<Character> repeatedChars(String s)
Practice1A.repeatedChars("hi") returns the empty list Practice1A.repeatedChars("EECS") returns the list ['E'] Practice1A.repeatedChars("EECS2030") returns the list ['E', '0']
s
- a non-null string