0% found this document useful (0 votes)
3 views2 pages

Java Recursive Function Outputs

21

Uploaded by

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

Java Recursive Function Outputs

21

Uploaded by

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

Directions : Show the output for each of the following code segments.

Once you have written answers to all questions, use JDoodle to check your answers.

1.

public static int bear( int x )


{
if( x > 0 )
return x + bear( x - 1 );
return 0;
}

//client code in the runner / main method


[Link]( bear(6) );

2.

public static int bear( int x )


{
if( x > 0 )
return x + bear( x - 1 );
return 0;
}

//client code in the runner / main method


[Link]( bear(11) );

3.

public static int car( int x )


{
if( x > 0 )
return car( x - 2 ) + 1;
return 0;
}

//client code in the runner / main method


[Link]( car(16) );

4.

public static int car( int x )


{
if( x > 0 )
return car( x - 2 ) + 1;
return 0;
}

//client code in the runner / main method


[Link]( car(26) );
5.

public static int bear( int x )


{
if( x > 0 )
return x + bear( x - 2 );
return 1;
}

//client code in the runner


[Link]( bear( 3 ) );

6.

public static int bear( int x )


{
if( x > 0 )
return x + bear( x - 2 );
return 1;
}

//client code in the runner


[Link]( bear( 8 ) );

7.

public static int car( int x )


{
if( x > 0 )
return car( x - 3 ) + 2;
return -1;
}

//client code in the runner


[Link]( car( 16 ) );

8.

public static int box( int x )


{
if( x > 0 )
return box( x - 2 ) + box( x – 3) + 1;
return 2;
}

//client code in the runner


[Link]( box( 17 ) );

You might also like