Recursion
int sum(int n)
1
, 2
, ..., n
.
long factorial(int n)
n
, n! = 1 * 2 * ... * n
.
boolean isPrime(int x, int divisor)
x
is a
prime number. Note that x
is not prime if x % divisor == 0
when divsior
is not equal to 1
or x
.
You may assume that the client invokes this method starting with
a divisor of 2
String reverse(String s)
s
in reverse order. For example,
reverse("banana")
returns "ananab"
.
String everySecondChar(String s, int idx)
s
starting from index idx
. For example,
everySecondChar("banana", 0)
returns "bnn"
,
and everySecondChar("banana", 1)
returns "aaa"
int sumEven(List<Integer> t)
t
.
List<Integer> allEven(List<Integer> t)
t
.
String everySecond(List<String> t, int idx)
t
starting from index idx
. For example,
suppose that:t
is the list ["a", "b", "c", "1", "2", "3"]
everySecond(t, 0)
returns "ac2"
,everySecond(t, 1)
returns "b13"
, andeverySecond(t, 6)
returns ""
.