Skip to content
Computer ApplicationsICSE Class 9 · Conditional Statements in Java

switch-case, break, default, Fall Through and Menu-Driven Programs in Java (ICSE Class 9)

Updated 18 October 2026 · Fact-checked

switch compares one expression with the constants of its case labels and starts executing at the matching case. Execution continues into the following cases until a break is met (fall through), so break normally ends each case. default runs when no case matches. Several cases can share one block by listing them together, and a menu-driven program uses switch to choose an operation from a menu.

With n = 2, case 2 has no break so it falls into case 3, and only that break leaves the switch; case 1 and default are skipped.

Illustration drawn for QuestionBuddy.

Understand switch-case, break, default, Fall Through and Menu-Driven Programs

Form.
switch (expression)
{
case value1: statements; break;
case value2: statements; break;
default: statements;
}
The expression is usually an int or a char value, and each case label is a constant of the same kind followed by a colon.

Working. The expression is evaluated once and matched with the case labels. Execution begins at the matching case. A break leaves the switch. default runs when no case matches; it is optional and may be the last label, where a break is not needed.

Fall through. Without break, execution continues into the next case whatever its label. This is sometimes used on purpose: stacking labels such as case 'a': case 'e': case 'i': case 'o': case 'u': lets several values share one block.

Differences from if. A switch tests one expression for equality with constants. It cannot test ranges such as marks >= 90 or conditions joined with &&; use an if-else-if ladder for those.

Menu-driven programs. Display a menu of numbered choices, read the choice with Scanner, and use switch to run the chosen operation. default reports an invalid choice. System.exit(0) ends the program at once; it is used, for example, for the "Exit" option.

Tracing method. Find the matching case, then read downwards, printing everything until a break or the closing brace.

Neighbouring topics: if, if-else and nested if are on the previous page of this chapter.

switch-case, break, default, Fall Through and Menu-Driven Programs: key facts

switch form
  • switch (expression)
  • case constant: statements; break;
  • default: statements
Usually an int or a char.
Fall through
No break: execution continues into the next case | break leaves the switch
Trace downwards from the match.
Grouped cases
case 4: case 6: case 9: one block for all | one break at the end
Saves repeated code.
Exit
System.exit(0) ends the program immediately | used for the Exit option of a menu
Ends the whole program.

How to answer switch-case, break, default, Fall Through and Menu-Driven Programs questions

Use this routine for a switch output question.

  1. 1Evaluate the switch expression.
  2. 2Find the case whose constant equals it; if none, go to default.
  3. 3Execute statements downwards from that label.
  4. 4Stop at the first break or the closing brace.
  5. 5Write the printed items in order, joined if print() is used.

switch-case, break, default, 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 of a vending machine

Suppose a vending machine asks you to press 1 for tea, 2 for coffee and 3 for soup, and says "invalid" for any other key.

Which Java statement fits and what plays the role of the invalid message?

Try it first, then show the solutionSolution
  1. The pressed key is the switch expression.
  2. Each key has its own case with break.
  3. default gives the invalid message.

Answer: A switch on the key with cases 1, 2, 3 and a default for the invalid message.

Memory hook: Cases for the known, default for the rest.

Tricks to remember switch-case, break, default, Fall Through and Menu-Driven Programs

Short memory aids. Say each one aloud once, then use it on a question the same day.

  • No break, no stop

    Without break execution falls into the next case.

    Use it when: Fall through.

  • Default is the safety net

    default catches every unmatched value.

    Use it when: Invalid input.

  • Stack the labels

    Put cases one under the other to share a block.

    Use it when: Vowel and month-type questions.

switch-case, break, default, Fall Through and Menu-Driven Programs: solved examples

Ordered from board level to HOTS. Try each one before you open the solution.

Example 1: Purpose of default · 1 mark · MCQBoard level

In a switch statement, default runs when:
(a) every case matches (b) no case matches (c) break is missing (d) the program ends

Try it first, then show the solutionSolution
  1. default is the fall-back for unmatched values.

Answer: (b) no case matches

Example 2: Fall through · 3 marks · Short answerHarder board level

Find the output (print is used, not println):

int d = 3;
switch (d)
{
case 1: System.out.print("A");
case 2: System.out.print("B"); break;
case 3: System.out.print("C");
case 4: System.out.print("D"); break;
default: System.out.print("E");
}
Try it first, then show the solutionSolution
  1. d = 3 matches case 3, so C is printed. (1 mark)
  2. There is no break after case 3, so execution falls into case 4 and prints D. (1 mark)
  3. The break after D leaves the switch; default is not run. Output: CD. (1 mark)

Answer: CD

Example 3: Grouped cases · 3 marks · Short answerHarder board level

Find the output for g = 'B' and for g = 'D':

switch (g)
{
case 'A': case 'B':
System.out.println("Good");
break;
case 'C':
System.out.println("Average");
break;
default:
System.out.println("Poor");
}
Try it first, then show the solutionSolution
  1. 'B' matches the second stacked label and execution runs the println below the group. (1 mark)
  2. Good is printed and break leaves the switch. (1 mark)
  3. 'D' matches no case, so default prints Poor. (1 mark)

Answer: Good for B; Poor for D

Example 4: Case study: a calculator menu · 4 marks · Case-basedHOTS / competency

A menu program uses:

int a = 12, b = 5;
double res = 0;
switch (ch)
{
case 1: res = a + b; break;
case 2: res = a - b; break;
case 3: res = a * b; break;
case 4: res = (double) a / b; break;
default: System.out.println("Invalid choice");
}
System.out.println("Result = " + res);

(i) Give the output for ch = 4. (1)
(ii) Give the output for ch = 9. (2)
(iii) What would ch = 2 give if the break after case 2 were missing? (1)

Try it first, then show the solutionSolution
  1. (i) res = 12.0 / 5 = 2.4, so Result = 2.4.
  2. (ii) default prints Invalid choice; res stays 0.0, so the last line prints Result = 0.0.
  3. (iii) Without the break, case 3 also runs and res = 12 * 5 = 60, so Result = 60.0.

Answer: (i) Result = 2.4 (ii) Invalid choice and then Result = 0.0 (iii) Result = 60.0

Example 5: Days in a month · 3 marks · Short answerHarder board level

Find the number of days stored for m = 6, m = 2 and m = 12:

int days;
switch (m)
{
case 2: days = 28; break;
case 4: case 6: case 9: case 11: days = 30; break;
default: days = 31;
}
Try it first, then show the solutionSolution
  1. m = 6 matches the stacked labels 4, 6, 9, 11: days = 30. (1 mark)
  2. m = 2 matches case 2: days = 28. (1 mark)
  3. m = 12 matches no case, so default gives 31. (1 mark)

Answer: 30, 28 and 31 (this ignores leap years)

Where students lose marks in switch-case, break, default, Fall Through and Menu-Driven Programs

The slips examiners see most often, and what to write instead.

  • Mistake: Forgetting break

    Each case is treated as separate.

    Wrong working

    case 1 prints A and case 2 prints B for the value 1: output A only

    Right working

    without break the output is AB

    Do this: Trace downwards until a break.

    Usually costs: 2 marks

  • Mistake: Writing a range in a case

    Ladder syntax is copied.

    Wrong working

    case >= 90:

    Right working

    Use an if-else-if ladder for ranges

    Do this: Case labels are constants.

    Usually costs: 1 mark

  • Mistake: Missing default in a menu

    Invalid input is not handled.

    Wrong working

    No default, nothing printed for 9

    Right working

    default prints Invalid choice

    Do this: Always add default to menus.

    Usually costs: 1 mark

Exam tips

  • Mark every break and say where the fall through stops.
  • State that default is optional.
  • In menu programs print the menu, read the choice, then switch.
  • Remember System.exit(0) ends the whole program, not just the switch.

Practice questions on switch-case, break, default, 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.

  1. Q1 · 1 mark · MCQBoard level

    Which keyword ends the execution of a case and leaves the switch?
    (a) exit (b) stop (c) break (d) default

    Hint

    It is also used in loops.

    Answer

    (c) break

  2. Q2 · 2 marks · Very short answerBoard level

    State the purpose of default in a switch and say whether it is compulsory.

    Hint

    Think of unmatched values.

    Answer

    default runs when no case label matches the expression. It is optional.

  3. Q3 · 2 marks · Short answerHarder board level

    Find the output:

    int ch = 2;
    switch (ch)
    {
    case 1: System.out.print(1);
    case 2: System.out.print(2);
    case 3: System.out.print(3);
    default: System.out.print(4);
    }
    Hint

    Look for break statements.

    Answer

    234 (case 2 matches; there is no break, so 3 and then default 4 also run)

  4. Q4 · 2 marks · Short answerHarder board level

    Explain why a switch cannot replace the ladder that checks marks >= 90, marks >= 75 and so on, and name the statement to use instead.

    Hint

    What does a case label hold?

    Answer

    A case label holds a single constant that is compared for equality, so ranges and conditions joined with logical operators cannot be written. An if-else-if ladder is used instead.

  5. Q5 · 3 marks · Short answerHOTS / competency

    Write a switch statement for a char variable c that prints "Stop" for 'R', "Get ready" for 'Y', "Go" for 'G' and "Invalid colour" for anything else.

    Hint

    Use println and break.

    Answer

    switch (c)
    {
    case 'R': System.out.println("Stop"); break;
    case 'Y': System.out.println("Get ready"); break;
    case 'G': System.out.println("Go"); break;
    default: System.out.println("Invalid colour");
    }

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. 1.What happens if break is missing?Show answer

    Execution falls through into the next case.

  2. 2.Which case runs if no label matches?Show answer

    default

  3. 3.Can a case label be a range?Show answer

    No, only a constant.

  4. 4.Which statement ends a program at once?Show answer

    System.exit(0)

  5. 5.Which two types are most often used as a switch expression in school programs?Show answer

    int and char.

  6. 6.What follows a case label?Show answer

    A colon.

switch-case, break, default, Fall Through and Menu-Driven Programs: frequently asked questions

Is fall through a mistake?

It is a rule of switch. It is useful for grouped cases but a bug if break is forgotten.

Can default be placed first?

It may appear anywhere, but writing it last is the usual form.

Do I need break after default?

Not when default is the last label.