πŸ“Š JAVA
Q. What is the output of the following code?
Code:
int x = 5;
if (x > 10) {
System.out.println(“x is greater than 10”);
} else if (x > 0) {
System.out.println(“x is greater than 0”);
} else {
System.out.println(“x is less than or equal to 0”);
}
  • (A) x is greater than 10
  • (B) x is greater than 0
  • (C) x is less than or equal to 0
  • (D) There is a syntax error in the code.
πŸ’¬ Discuss
βœ… Correct Answer: (B) x is greater than 0

Explanation: The if-else statement tests the value of x against each condition in turn. Since x is greater than 0 but not greater than 10, the code for the second condition is executed.

Explanation by: Deepak Sahoo
The if-else statement tests the value of x against each condition in turn. Since x is greater than 0 but not greater than 10, the code for the second condition is executed.

πŸ’¬ Discussion


πŸ“Š Question Analytics

πŸ‘οΈ
224
Total Visits
πŸ“½οΈ
3 y ago
Published
πŸŽ–οΈ
Deepak Sahoo
Publisher
πŸ“ˆ
82%
Success Rate