Question: Given the following code: static void showOutput ( int mark ) { if ( mark = = 0 ) { System.out.print ( *

Given the following code:
static void showOutput(int mark){
if (mark ==0){
System.out.print("*");
}
else {
System.out.println("[");
showOutput(mark -1);
System.out.print(",");
showOutput(mark -1);
System.out.println("]");
}
}
Can you determine what is produced by the following subroutine calls:
showOutput(0), showOutput(1), showOutput(2), and showOutput(3)?
a.
showOutput(0) outputs: *
showOutput(1) outputs: [*,*]
showOutput(2) outputs: [[*,*],[*,*]]
showOutput(3) outputs: [[[*,*],[*,*]],[[*,*],[*,*]]]
b.
showOutput(0) outputs: [
showOutput(1) outputs: *,*
showOutput(2) outputs: [[],[]]
showOutput(3) outputs: [[[*,*],[*,*]],[[*,*],[*,*]]]

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!