public class Test4A extends Object
Modifier and Type | Method and Description |
---|---|
static int |
findZero(List<Integer> t)
Returns the index of the element equal to zero in the
specified sorted list.
|
static boolean |
isPalindrome(String s)
Returns true if the specified string is a palindrome.
|
static void |
partition(List<Integer> t)
Re-orders the elements of the argument list t so that
all of the negative elements of t are in the front part
of the list and all of the positive elements of t are
in the back part of the list.
|
static String |
repeat(String s,
int n)
Returns the string formed by repeating the specified string n times; each
repetition of s is separated by a comma followed by space.
|
public static String repeat(String s, int n)
repeat("cat", 1) returns the string equal to "cat" repeat("rat", 2) returns the string equal to "rat, rat" repeat("la", 3) returns the string equal to "la, la, la"
s
- the string to be repeatedn
- the number of times to repeat spublic static boolean isPalindrome(String s)
isPalindrome("a") returns true isPalindrome("at") returns false isPalindrome("tat") returns true isPalindrome("refer") returns true isPalindrome("refers") returns false
s
- a stringpublic static void partition(List<Integer> t)
Zero is considered to be a positive number for the purposes of this method.
For example, a possible solution results in the following:
if t is [] then partition(t) makes t [] if t is [1] then partition(t) makes t [1] if t is [-1, 2] then partition(t) makes t [-1, 2] if t is [2, -1] then partition(t) makes t [-1, 2] if t is [8, -2, 1] then partition(t) makes t [-2, 1, 8] if t is [1, -5, -9, 4] then partition(t) makes t [-5, -9, 4, 1] if t is [-3, 7, -1, 3, -5] then partition(t) makes t [-3, -1, -5, 7, 3]
t
- a list of integerspublic static int findZero(List<Integer> t)
The computational complexity of the method is O(log n) where n is the size of the list t.
t
- a sorted list