Switch Case, Fall Through and Menu-driven Programs in Java (ICSE Class 10)
Updated 17 October 2026 · Fact-checked
switch (expression) compares the expression with each case label and starts executing at the matching label. Without a break, execution carries on into the next case (fall through) until a break or the end of the switch. default runs when no label matches. A menu-driven program shows a list of choices, reads the choice and uses switch (or if-else-if) to run the chosen task.
With choice = 2, the red break bar stops after case 2; without it, execution falls through case 3 and default too.
Illustration drawn for QuestionBuddy.
Understand Switch Case, Fall Through and Menu-driven Programs
Syntax.
switch (expression) {
case value1: statements; break;
case value2: statements; break;
default: statements;
}Rules.
- The expression is of type
int,char(alsobyte,shortand, in modern Java,String); notdouble,floatorboolean. - Each case label is a constant (a literal such as
3or'a') and labels must be different. switchtests only for equality; ranges and conditions such asmarks > 50need if-else-if.defaultis optional and runs when no case matches. It is usually written last.breakleaves the switch.
Fall through. If a matching case does not end with break, control continues into the following case statements (whether or not their labels match) until a break or the closing brace. This is sometimes used on purpose to give several labels the same action: case 'a': case 'e': case 'i': ... share one set of statements.
switch versus if-else-if. Use switch when one variable is compared with several fixed values (menus, vowels, day numbers); use if-else-if for ranges and compound conditions.
Menu-driven program. Print the list of options, read the choice and run the matching code; default handles a wrong choice. System.exit(0); ends the program immediately; the 0 means a normal end.
Variables inside cases. All cases share one block, so each variable declared in a case needs its own name (double s in case 1 and double l in case 2).
Neighbouring topics: the basic if and if-else constructs are on the chapter page.
Switch Case, Fall Through and Menu-driven Programs: key facts
- Switch rules
- Expression: int, char (byte, short, String)
- Case labels: constants, all different
- Tests equality only
- default optional
- double, float and boolean cannot be used.
- Fall through
- No break: control continues into the next case | break: leaves the switch
- The last case may omit break.
- Shared action for several labels
- case 'a': case 'e': case 'i':
- statements;
- break;
- Empty cases fall through to the first statements.
- Terminating a program
- System.exit(0); | 0 means normal end
- Often used in the exit option of a menu.
How to answer Switch Case, Fall Through and Menu-driven Programs questions
Use this routine for switch output questions.
- 1Evaluate the expression and find the first case label equal to it (or default if none).
- 2Start executing from that label.
- 3Keep executing the statements of the following cases until you meet a break or the end of the switch.
- 4Remember that default also executes when control falls into it from above.
- 5Write the printed output exactly, using print or println as given.
Switch Case, Fall Through and Menu-driven Programs in real life
The idea, met in an everyday situation. Answer the question in your own words, then compare with the model answer. The one-line hook is what to remember.
Menu as a canteen board
Suppose a canteen board lists 1 for tea, 2 for juice, 3 for sandwich and the student presses a number on a keypad.
Which construct suits this, and what should happen if 7 is pressed?
Try it first, then show the solutionSolution
- A single value is compared with fixed choices: switch fits well.
- The default branch handles the wrong number, for example by printing "Invalid choice".
Answer: A switch; default handles 7 with an error message.
Memory hook: Menu = switch, wrong choice = default.
Tricks to remember Switch Case, Fall Through and Menu-driven Programs
Short memory aids. Say each one aloud once, then use it on a question the same day.
Break is the brake
Without a break the switch keeps rolling downhill into the next case.
Use it when: Fall-through output.
Switch tests =, not >
If the condition has > or <, use if-else-if.
Use it when: Choosing a construct.
Default is the safety net
default catches every value that no case caught.
Use it when: Menu programs.
Switch Case, Fall Through and Menu-driven Programs: solved examples
Ordered from board level to HOTS. Try each one before you open the solution.
Example 1: A simple switch · 1 mark · Very short answerBoard level
Write the output:
int d = 3;
switch (d) {
case 1: System.out.println("Mon"); break;
case 2: System.out.println("Tue"); break;
case 3: System.out.println("Wed"); break;
default: System.out.println("Other");
}Try it first, then show the solutionSolution
- d = 3 matches case 3, which prints Wed, and break leaves the switch.
Answer: Wed
Example 2: Fall through · 3 marks · Short answerHarder board level
Write the output for g = 'A', g = 'C' and g = 'D':
switch (g) {
case 'A': System.out.print("Excellent ");
case 'B': System.out.print("Good "); break;
case 'C': System.out.print("Fair ");
default: System.out.print("Check");
}Try it first, then show the solutionSolution
- g = 'A': prints Excellent; no break, so case 'B' prints Good; then break. (1 mark)
- g = 'C': prints Fair; no break, so control falls into default and prints Check. (1 mark)
- g = 'D': no label matches, so default prints Check. (1 mark)
Answer: g = 'A': Excellent Good ; g = 'C': Fair Check ; g = 'D': Check
Example 3: Sharing an action · 3 marks · Short answerHarder board level
Complete the code so that vowels print "vowel" and everything else "other", then state the output for 'e' and 'z':
switch (ch) {
case 'a':
case 'e':
case 'i':
case 'o':
case 'u':
System.out.println("vowel"); break;
default:
System.out.println("other");
}Try it first, then show the solutionSolution
- For 'e' control enters at case 'e', and the empty cases fall through to println("vowel"), then break. (1 mark)
- For 'z' no label matches, so default prints other. (1 mark)
- The empty cases are intentional fall through to share one action. (1 mark)
Answer: 'e': vowel; 'z': other
Example 4: Case study: a menu-driven program · 4 marks · Case-basedHOTS / competency
A student writes:
import java.util.Scanner;
public class Menu {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
System.out.println("1. Square area");
System.out.println("2. Rectangle area");
System.out.print("Enter choice: ");
int ch = in.nextInt();
switch (ch) {
case 1:
System.out.print("Side: ");
double s = in.nextDouble();
System.out.println("Area = " + s * s);
break;
case 2:
System.out.print("Length and breadth: ");
double l = in.nextDouble(), b = in.nextDouble();
System.out.println("Area = " + l * b);
break;
default:
System.out.println("Wrong choice");
}
}
}(i) Give the last line printed for inputs: 1 then 4. (1)
(ii) Give the last line for inputs: 2 then 3 and 2.5. (1)
(iii) Give the output for the choice 5. (1)
(iv) What would happen for choice 1 if the first break were removed? (1)
Try it first, then show the solutionSolution
- (i) s = 4.0, so s * s = 16.0: Area = 16.0.
- (ii) l = 3.0, b = 2.5, l * b = 7.5: Area = 7.5.
- (iii) 5 matches no label, so default prints Wrong choice.
- (iv) After printing the square area, control would fall into case 2 and ask for the length and breadth.
Answer: (i) Area = 16.0 (ii) Area = 7.5 (iii) Wrong choice (iv) it would also run case 2 and ask for length and breadth
Example 5: Reading if-else-if and separate ifs · 3 marks · Short answerHarder board level
Write the output:
int m = 68;
String g;
if (m >= 90) g = "A";
else if (m >= 75) g = "B";
else if (m >= 60) g = "C";
else g = "D";
int x = 15;
if (x > 10) System.out.print("P");
if (x > 20) System.out.print("Q");
else System.out.print("R");
System.out.println(g);Try it first, then show the solutionSolution
- In the ladder, 68 fails >= 90 and >= 75 and passes >= 60, so g = "C". (1 mark)
- The first if prints P since 15 > 10. The next if-else is a separate statement: 15 > 20 is false, so the else prints R. (1 mark)
- Finally println(g) prints C on the same line: PRC. (1 mark)
Answer: PRC
Where students lose marks in Switch Case, Fall Through and Menu-driven Programs
The slips examiners see most often, and what to write instead.
Mistake: Stopping at the matching case when there is no break
Execution falls through to later cases.
Wrong working
n = 2 prints B only
Right working
n = 2 prints B and then C (until break)
Do this: Look for the next break each time.
Usually costs: 1 to 2 marks
Mistake: Using a range or condition as a case label
case labels must be constants; switch tests equality only.
Wrong working
case marks > 50:
Right working
Use if (marks > 50) ... else if ...
Do this: Choose if-else-if for ranges.
Usually costs: 1 mark
Mistake: Using the same variable name in two cases
All cases share one block, so a repeated declaration is a compile-time error.
Wrong working
case 1: double x = ...; case 2: double x = ...;
Right working
Use different names or declare the variable before the switch.
Do this: Declare once before the switch.
Usually costs: 1 mark
Exam tips
- Menu programs: print the menu, read the choice, switch, and give a default message.
- End each case with break unless fall through is wanted; say so when it is intentional.
- Remember System.exit(0); for an exit option.
- State "break is missing, so fall through occurs" in explanations; it earns the reasoning mark.
Practice questions on Switch Case, Fall Through and Menu-driven Programs
Write each answer on paper first. Open the hint only if you are stuck, and the answer only when you have finished.
Q1 · 1 mark · MCQBoard level
The expression of a switch statement can NOT be of the type:
(a) int (b) char (c) double (d) shortHint
Switch needs exact matches.
Answer
(c) double
Q2 · 1 mark · Very short answerBoard level
What is meant by fall through in a switch statement?
Hint
What if break is missing?
Answer
When a matching case has no break, control continues into the statements of the following cases until a break or the end of the switch.
Q3 · 2 marks · Short answerHarder board level
Write the output:
int n = 6; switch (n % 3) { case 0: System.out.print("zero "); case 1: System.out.print("one "); case 2: System.out.print("two "); break; default: System.out.print("none"); }Hint
Evaluate n % 3 first; where does execution start and stop?
Answer
zero one two (6 % 3 = 0, so case 0 prints "zero ", falls through case 1 and case 2, and the break stops it)
Q4 · 3 marks · Short answerHarder board level
Rewrite using switch:
if (c == '+') r = a + b; else if (c == '-') r = a - b; else r = 0;Hint
c is a char; end each case with break.
Answer
switch (c) {
case '+': r = a + b; break;
case '-': r = a - b; break;
default: r = 0;
}Q5 · 1 mark · Assertion-reasonHOTS / competency
Assertion (A): Missing break statements can make more than one case execute.
Reason (R): After a matching case, control passes to the next case label without testing it when no break is met.
(a) Both A and R are true and R is the correct explanation of A. (b) Both A and R are true but R is not the correct explanation of A. (c) A is true but R is false. (d) A is false but R is true.Hint
Does the next label get tested?
Answer
(a) Both are true and R explains A.
Test your recall
Answer in your head or on paper first, then open the card. Pulling an answer out of memory makes it stick far better than re-reading.
1.What does break do in a switch?Show answer
Leaves the switch statement.
2.When does default run?Show answer
When no case matches (or when control falls into it).
3.Can a switch test n > 5?Show answer
No; it tests equality only.
4.What does System.exit(0) do?Show answer
Ends the program immediately; 0 means a normal end.
5.Name two types allowed in a switch expression.Show answer
int and char.
6.Can two case labels have the same value?Show answer
No; labels must be different constants.
Switch Case, Fall Through and Menu-driven Programs: frequently asked questions
What is the difference between switch and if-else-if?
Switch compares one expression with fixed constant values; if-else-if can test ranges and compound conditions. Switch can fall through; if-else-if cannot.
Is default compulsory?
No, but it is good practice, especially in menus, to handle a wrong choice.
Where can default be placed?
Normally last. If placed elsewhere and not ended with break, execution can fall into the next case.