0
Can someone explain me what would be the outcome when n=3.
public static void countup(int n) { if (n == 0) { System.out.println("Blastoff!"); } else { countup(n - 1); System.out.println(n); } }
6 Respuestas
+ 1
The output is 2 but you can test youself you code on the java console
Think to it the next time
0
Okay...Thank you, now i have mentioned in the tags
0
Heuba Batomen i am sorry but output is
Blastoff!
1
2
3
What i dont understand is why is there 1,2 and 3 in the output
0
Let's check the coutup documentation the awser is there
It's easy
0
Why output
1
2
3. ????
Because when "n" is 0 , The value of the argument "n" in the countup(n-1) is "1".
it will print 1.
similarly when it return back to the calling function the value of " n" is "2". So it will print 2.
----------------------------------------
when if(0==0) print BasOff
countup(1-1) when return back "n" is "1" print "1"
countup(2-1) when return back "n" is "2" print "2"
countup(3-1) when return back "n" is "3" print "3"
Ok.