in Object Oriented Programming recategorized
1,992 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
2.0k views

2 Comments

option B) 95 ?
1
1
0
0

6 Answers

3 votes
3 votes

Answer : 95

by

3 Comments

can you please explain it theoretically..

i am unable to understand why every time it is substracting when return stmt is given after the completion of recursion...

can anybody please explain
0
0
Because of the statement return(x-1); we have to subtract 1 and return
0
0
thank you
0
0
2 votes
2 votes
Option 2

 

CBSE(60) ->

                 60<100 so, x=CBSE(70)

                       ...................................80

                                           ............................................90

                                                  ......................................................100    

                                                                                     100  is not < 100  SO CBSE(100) Returns 100-1=99

            cbse(90) returns 98

      cbse(80) returns 97

   cbse(70)returns 96

cbse(60) returns 95

 

therefore ans 95
0 votes
0 votes
Answer is 95
0 votes
0 votes
option B is coorect
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