A+ Computer Science – Recursion Worksheet 1
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.
static void fun1(int x)
{
if(x>=1){
[Link](x);
fun1(x-1);
}
}
static void fun2(int x)
{
if(x<1){
[Link](x);
}else{
[Link](x);
fun2(x-1);
}
}
static int fun3(int x)
{
if (x<1)
return x;
else
return x + fun3(x-2);
}
static int fun4( int x, int y)
{
if( y == 2)
return y;
else
return fun4( x, y - 1) + x;
}
///////////////////////////////////
//runner code in the main of another class
fun1(5); //line 1 1. _______________
fun2(6); //line 2 2. _______________
[Link]( fun3(4) ); //line 3 3. _______________
[Link]( fun4(3, 6) ); //line 4 4. _______________
[Link]( fun4(4 , 2)); //line 5 5. _______________
© A+ Computer Science – Worksheet – [Link]