For each call to the following method indicate what
console output is produced
public void mysteryXY ( int x, int y) {
if ( y==1){
System.out.print(x);
}else{
System.out.print(x * y + " , ");
mysteryXY( x, y-1);
System.out.print(" , " + x * y);
}
}
mysteryXY(5,2)
mysteryXY(10,1)
Answer:
First call:
For the call mysteryXY(5,2)
First, mysteryXY is called with x=5 and y=2
As y is not equal to 1 , else part is executed:
First line of else block is:
System.out.print(x * y + " , ");
which prints 10 ,
Then second line of else block makes a call mysteryXY(5, 1)
As y=1 in this call, This call goes to if block and prints 5 , and control goes out of the function and back to the original call where x=5 and y=2
Then third line of else block is executed which prints , 10
Output:

Second call:
In the call mysteryXY(10,1) x=10 and y=1 , so it goes to the if block only and simply prints x
So,
10
output:

Hope you like it!
Please provide comments if you have any doubts!
For each call to the following method indicate what console output is produced public void mysteryXY...