Chapter 8 Recursion Ws 3
Chapter 8 Recursion Ws 3
Recursion Practice
(and then there’s more)
a) smile!
b) smile!smile!
c) smile!smile!smile!
d) smile!smile!smile!smile!
e) smile!smile!smile!smile!smile!smile!smile!smile!smile!smile!
f)
22. When smile(4) is called, how many times will smile be called including the initial call?
a) 2
b) 3
c) 4
d) 5
e) 10
23. What is displayed when the following method is called with splat(**)?
public static void splat(String s)
{
if(s.length() < 8)
splat(s+s);
System.out.println(s);
}
a) **
b) ****
c) ********
d) ********
**
e) ********
****
**
24. Lexi is a cheerleader and a programmer. She has written the following recursive mthod that
is supposed to generate the cheer “2 4 6 8 who do we appreciate!”:
a) p
b) pa
c) ya
d) aya
e) paya
a) 0
b) 05
c) 0 5 10
d) 0 5 10 15
e) 0 5 10 15 20
a) val – 2
b) val%2
c) (val-1) % 2
d) val /2
e) (val-1) /2
a) 1
b) 4
c) 14
d) 104
e) 401
30. Consider the following two methods that are declared within the same class:
public int supplement (int value)
{
if(value < 50)
return reduce (value + 10);
else
return value;
}