Consider the following program segment and select the output of the same when n = 10:
Advertisements
Question
Consider the following program segment and select the output of the same when n = 10:
switch(n)
{Case 10: System.out.println(n*2);
case 4: System.out.println(n*4); break;
default : Syslem.out.println(n);
}Options
20
4010
420, 40
10
10
MCQ
Advertisements
Solution
20
40
Explanation:
The value of n = 10 matches the 1st case, so n*2 = 20 is printed. Since there is no break, the control also goes to the next case and printsn*4 = 40 in a new line. Then, a break is encountered.
shaalaa.com
Introduction of Conditional Statements in Java
Is there an error in this question or solution?
Chapter 1: Revision of Class 9 Syllabus - Exercises [Page 44]
