...
OOPS
August 25, 2024
JAVA
August 25, 2024
OOPS
August 25, 2024
JAVA
August 25, 2024

OOPS

Question 178
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 ?
A
59
B
95
C
69
D
99
Question 178 Explanation: 
Main program will call the function CBSE(60)
According to the function definition,
Function call CBSE(100) will give the value of 99,
100<100 condition is false and it will return x-1 which is 99
x=CBSE(90)
90<100 is true—-> x=CBSE(100) and it will return x-1
CBSE(100) will return 99 to Function CBSE(90) and this function will return to 98(99-1).
Repeat this procedure,
CBSE(60) will return 95
Correct Answer: B
Question 178 Explanation: 
Main program will call the function CBSE(60)
According to the function definition,
Function call CBSE(100) will give the value of 99,
100<100 condition is false and it will return x-1 which is 99
x=CBSE(90)
90<100 is true—-> x=CBSE(100) and it will return x-1
CBSE(100) will return 99 to Function CBSE(90) and this function will return to 98(99-1).
Repeat this procedure,
CBSE(60) will return 95
0 0 votes
Article Rating
Subscribe
Notify of
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x
error: Alert: Content selection is disabled!!