OOPS
August 25, 2024JAVA
August 25, 2024OOPS
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 ?
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 ?
59 | |
95 | |
69 | |
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
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
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
Subscribe
Login
0 Comments