1,162 views

Consider the following JAVA program:

public class First {
public static int CBSE (int x) {
if (x < 100)x = CBSE (x+10);
return (x-1);
}
public static void main(String[]args){
System.out.print(First.CBSE(60));
}
}


What does this program print?

1. $59$
2. $95$
3. $69$
4. $99$

option B) 95 ?

Answer should be 95. Since recursively Class is calling the method CBSE and when first time recursion fails the value of x was 100, at this time there will be 5 recursion STACK corresponding to x values (60,70,80,90,100). Now each recursion stack get removed by decrementing the value of x by 1 each time. Hence finally when all recursive stack over it has decremented total of 5. that is 100-5 = 95.

by

i am getting option d