in Object Oriented Programming recategorized
902 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$
in Object Oriented Programming recategorized
902 views

2 Comments

option B) 95 ?
1
1
0
0

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
by
0 votes
0 votes

 

i am getting option d

Answer:

Related questions

Quick search syntax
tags tag:apple
author user:martin
title title:apple
content content:apple
exclude -tag:apple
force match +apple
views views:100
score score:10
answers answers:2
is accepted isaccepted:true
is closed isclosed:true