0
Mysterious output of static method
Pls explain public class First { public static int Cb(int x){ if(x < 100) x = Cb(x + 10); return(x - 1); } public static void main(String[] args) { System.out.print(First.Cb(60)); //95 } }
2 Respostas
+ 3
No it is correct.when you enter 60, recursion happens 4 times.and by the 5th recursion,the x value is 100 and if statement is not executed and then x-1 happens 5 times due to return statement.so answer is 95 is correct.
0
i have found why output is 95. i had to test various return(x - n) n eg 2,3,4.