recategorized
2,051 views
0 votes
0 votes

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$
recategorized

6 Answers

0 votes
0 votes

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.

edited by
Answer:

Related questions

3 votes
3 votes
2 answers
4
go_editor asked Aug 1, 2016
3,736 views
Which one of the following is correct?Java applets cannot be written in any programming languageAn applet is not a small programAn applet can be run on its ownApplets are...