I'm have a problem understanding how we are getting the answer written below. Can someone please explain the steps to me please? I'm mainly confused as to which steps occur, and also what happens at the "a = b + mystery( b - 1)". If the first output is 8 and 10...
a = 10 + 9, and then I have no idea what happens...
I was hoping someone could write out the proper steps for me, as this has been lingering for the past few hours. I think i simply dont understand the math or syntax. It's a late night...thanks in advance.
The answers are:
8 10
9 11
Whoa
10 8
13 11
12 10
a = 10 + 9, and then I have no idea what happens...
I was hoping someone could write out the proper steps for me, as this has been lingering for the past few hours. I think i simply dont understand the math or syntax. It's a late night...thanks in advance.
int mystery( int a )
{
int b = a + 2;
if ( b <= 11 )
{
System.out.println( a + " " + b );
a = b + mystery( b - 1 );
}
else
{
System.out.println( "Whoa" );
b = a - 2;
}
System.out.println( a + " " + b );
return a - b;
}
The answers are:
8 10
9 11
Whoa
10 8
13 11
12 10