0% found this document useful (0 votes)
6 views1 page

Java Recursion Output Analysis

The document is a worksheet for A+ Computer Science focusing on recursion. It contains several recursive functions and prompts the user to fill in the expected outputs for each function call. The functions include fun1, fun2, fun3, and fun4, each demonstrating different recursive behaviors.

Uploaded by

zaidcalls
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views1 page

Java Recursion Output Analysis

The document is a worksheet for A+ Computer Science focusing on recursion. It contains several recursive functions and prompts the user to fill in the expected outputs for each function call. The functions include fun1, fun2, fun3, and fun4, each demonstrating different recursive behaviors.

Uploaded by

zaidcalls
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd

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]

You might also like