πŸ“Š JAVA
Q. What is the output of the following code?
Code:
int x = 5;
switch (x) {
case 1:
System.out.println(“x is 1”);
break;
case 5:
System.out.println(“x is 5”);
break;
default:
System.out.println(“x is not 1 or 5”);
}
  • (A) x is 1
  • (B) x is 5
  • (C) x is not 1 or 5
  • (D) There is a syntax error in the code.
πŸ’¬ Discuss
βœ… Correct Answer: (B) x is 5

Explanation: The switch statement tests the value of x against each case, and executes the code for the first matching case. In this case, the code for the case where x equals 5 is executed.

Explanation by: Deepak Sahoo
The switch statement tests the value of x against each case, and executes the code for the first matching case. In this case, the code for the case where x equals 5 is executed.

πŸ’¬ Discussion


πŸ“Š Question Analytics

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