A+ Computer Science – Recursion Worksheet 3
DIRECTIONS : Fill in each blank with the correct answer/output. Assume each
statement happens in order and that one statement may affect the next statement.
Some sections might print more than once.
public static int fun(int x)
{
if(x<1)
return 1;
else
return x+fun(x-1)+fun(x-2);
}
public static int go(int x)
{
if(x<1)
return 1;
else
return x+go(x-2)+go(x-3);
}
public static int fly(int x)
{
if(x<1)
return 1;
else
return x+fly(x-4)+fly(x-1);
}
///////////////////////////////////
//runner code in the main of another class
[Link]("#1 - "+fun(2));
[Link]("#2 - "+fun(6));
[Link]("#3 - "+go(5));
[Link]("#4 - "+go(3));
[Link]("#5 - "+fly(4));
[Link]("#6 - "+fly(5));
© A+ Computer Science – Worksheet – [Link]