ICSE Class 10 · Computer Applications (Java) · Menu driven programs 2027

Menu driven program in Java for ICSE, with an answer template that never forgets the default case.

A menu driven program in Java for ICSE shows the user a numbered or lettered list, reads a choice and uses switch to run only the matching task. The marks go to a fixed shape: menu, input, one case per option with its break, and a default case for a wrong choice. This page gives that shape as a five-part Section B template, then four full programs that each add one new idea, all run in Java 21 with the real output. In our live mini batch, students write menus to this template until it is automatic.

Live online · a five-part Section B template · four full menu programs · switch case questions · first class free

Start here

Courses where menu programs are taught

The ICSE Java course in which the mini batch writes these menus, the Class 11 and 12 Computer Science course where menus grow into larger ISC programs, and the data structures course for a student who wants to see how a menu becomes the front of a real application.

Ans. The short version

A menu driven program in Java for ICSE Class 10 prints a list of options, reads the user's choice with Scanner, and uses a switch statement to run only the code for that choice. A full-mark Section B answer has five parts: the printed menu, the choice read in, one case per option, a break ending every case, and a default case printing a message such as "Invalid choice" for any other input. Stacked labels let 'A' and 'a' share code. Modern Age Coders teaches this live in a Tuesday and Wednesday mini batch in India, or one to one at the family's time.

Q1. What should a menu driven answer look like in Section B?

Menu driven program Section B template: five parts, in order

Write the same five parts every time, whatever the options do. The examiner looks for each part, and a missing default case or a missing break is the commonest way to drop marks on an otherwise working menu.

PartWhat to writeWhy it matters
1. The menuOne System.out.println per option, numbered or lettered exactly as the question words themThe user, and the examiner, must see what each choice does
2. The choiceint ch = sc.nextInt(); or char ch = sc.next().charAt(0);The type of ch decides how the case labels are written
3. One case per optioncase 1: followed by the full logic for that option, including its own inputEach option is a small program; read only the data that option needs
4. A break per casebreak; as the last line of every caseWithout it, control falls into the next case and runs that code too
5. The default casedefault: System.out.println("Invalid choice");The question almost always says "for an incorrect choice, display an appropriate message"; this is that message

Program 1: the template filled in, a temperature menu

TempMenu.javaint choice, two options
import java.util.Scanner;
class TempMenu {
    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        System.out.println("1. Celsius to Fahrenheit");     // part 1: menu
        System.out.println("2. Fahrenheit to Celsius");
        System.out.print("Enter your choice: ");
        int ch = sc.nextInt();                              // part 2: choice
        switch (ch) {
            case 1:                                         // part 3: one case per option
                System.out.print("Temperature in Celsius: ");
                double c = sc.nextDouble();
                double f = 9.0 / 5 * c + 32;
                System.out.println("In Fahrenheit = " + f);
                break;                                      // part 4
            case 2:
                System.out.print("Temperature in Fahrenheit: ");
                double fa = sc.nextDouble();
                double ce = 5.0 / 9 * (fa - 32);
                System.out.println("In Celsius = " + ce);
                break;
            default:                                        // part 5
                System.out.println("Invalid choice");
        }
    }
}

9.0 / 5 is written with a decimal point on purpose. 9 / 5 in int arithmetic is 1, and every answer in case 1 would be wrong.

VariableTypePurpose
chintmenu choice entered by the user
c, fdoubleCelsius input and Fahrenheit result (case 1)
fa, cedoubleFahrenheit input and Celsius result (case 2)
scScannerreads keyboard input
Sample runsJava 21
1. Celsius to Fahrenheit
2. Fahrenheit to Celsius
Enter your choice: 2
Temperature in Fahrenheit: 98.6
In Celsius = 37.0

1. Celsius to Fahrenheit
2. Fahrenheit to Celsius
Enter your choice: 1
Temperature in Celsius: 37
In Fahrenheit = 98.60000000000001

1. Celsius to Fahrenheit
2. Fahrenheit to Celsius
Enter your choice: 3
Invalid choice

The long tail on 98.60000000000001 is how a double stores 1.8; it is correct Java output, not a bug. Always show one run that reaches the default case when you test a menu.

Q2. How do you write a menu with letters instead of numbers?

Switch case programs ICSE Class 10: a char menu with stacked case labels

Read the choice as a char with sc.next().charAt(0) and put each letter in single quotes. To accept both capital and small letters, stack two labels on one block: case 'G': case 'g':. This is deliberate fall-through, the one place it helps.

Program 2: GCD or LCM of two numbers, chosen by a letter

GcdLcm.javachar choice, stacked labels
import java.util.Scanner;
class GcdLcm {
    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        System.out.println("G. Greatest common divisor");
        System.out.println("L. Lowest common multiple");
        System.out.print("Enter G or L, then two numbers: ");
        char ch = sc.next().charAt(0);
        int a = sc.nextInt(), b = sc.nextInt();
        int x = a, y = b;
        while (y != 0) {          // Euclid: replace (x, y) by (y, x % y)
            int r = x % y;
            x = y;
            y = r;
        }
        int gcd = x;
        switch (ch) {
            case 'G':
            case 'g':
                System.out.println("GCD = " + gcd);
                break;
            case 'L':
            case 'l':
                System.out.println("LCM = " + (a * b / gcd));
                break;
            default:
                System.out.println("Wrong letter, enter G or L");
        }
    }
}

The GCD is worked out once, before the switch, because both options need it. The LCM then comes from the rule a x b = GCD x LCM.

VariableTypePurpose
chcharthe letter chosen, G or L in either case
a, bintthe two numbers entered
x, yintworking copies changed by Euclid's loop
rintremainder of x divided by y
gcdintgreatest common divisor of a and b
Sample runsJava 21
G. Greatest common divisor
L. Lowest common multiple
Enter G or L, then two numbers: G 84 36
GCD = 12

G. Greatest common divisor
L. Lowest common multiple
Enter G or L, then two numbers: l 84 36
LCM = 252

G. Greatest common divisor
L. Lowest common multiple
Enter G or L, then two numbers: x 4 6
Wrong letter, enter G or L

The small l reaches the LCM block through the stacked label. Copies x and y are used in the loop so that a and b are still intact for the LCM.

Program 3: a pattern or a series, the classic two-option menu

Many Section B menus pair a nested loop pattern with the sum of a series. Each case is then a complete small program; the switch only chooses between them.

PatSeries.javapattern or series
import java.util.Scanner;
class PatSeries {
    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        System.out.println("1. Symbol pattern");
        System.out.println("2. Sum of the series 2/3 + 4/5 + 6/7 + ...");
        System.out.print("Enter choice and n: ");
        int ch = sc.nextInt();
        int n = sc.nextInt();
        switch (ch) {
            case 1:
                for (int i = 1; i <= n; i++) {
                    for (int j = 1; j <= i; j++) {
                        if (j % 2 == 1)
                            System.out.print("* ");
                        else
                            System.out.print("# ");
                    }
                    System.out.println();
                }
                break;
            case 2:
                double s = 0;
                for (int k = 1; k <= n; k++)
                    s = s + (2.0 * k) / (2 * k + 1);
                System.out.println("Sum = " + s);
                break;
            default:
                System.out.println("Choose 1 or 2");
        }
    }
}

Term k is 2k over 2k + 1. Writing 2.0 * k makes the division real; with 2 * k every term would be 0.

Sample runsJava 21
1. Symbol pattern
2. Sum of the series 2/3 + 4/5 + 6/7 + ...
Enter choice and n: 1 5
*
* #
* # *
* # * #
* # * # *

1. Symbol pattern
2. Sum of the series 2/3 + 4/5 + 6/7 + ...
Enter choice and n: 2 4
Sum = 3.212698412698413

1. Symbol pattern
2. Sum of the series 2/3 + 4/5 + 6/7 + ...
Enter choice and n: 7 3
Choose 1 or 2

Check case 2 by hand for n = 2: 2/3 + 4/5 is about 0.667 + 0.8, which is 1.467. One quick check like this catches a wrong term formula before the examiner does.

The loop rules behind case 1 are set out on pattern programs for ICSE, and case 2 belongs to the family on series programs in Java for ICSE. A menu over three number checks, spy, Niven and neon, is worked on special number programs in Java.

Q3. How do you make a menu repeat until the user exits?

A repeating menu driven program: do-while, methods and an exit option

Wrap the menu and the switch in a do-while loop that runs until the exit choice is entered. do-while fits because the menu must appear at least once. Moving each option's work into a method keeps the switch short and shows user-defined methods at the same time.

Program 4: a wallet with deposit, withdraw, balance and exit

Wallet.javamenu inside do-while
import java.util.Scanner;
class Wallet {
    double balance = 0;
    void deposit(double amt) {
        balance = balance + amt;
        System.out.println("Deposited. Balance = " + balance);
    }
    void withdraw(double amt) {
        if (amt > balance)
            System.out.println("Not enough balance");
        else {
            balance = balance - amt;
            System.out.println("Withdrawn. Balance = " + balance);
        }
    }
    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        Wallet w = new Wallet();
        int ch;
        do {
            System.out.println("1. Deposit  2. Withdraw  3. Balance  4. Exit");
            System.out.print("Choice: ");
            ch = sc.nextInt();
            switch (ch) {
                case 1:
                    System.out.print("Amount: ");
                    w.deposit(sc.nextDouble());
                    break;
                case 2:
                    System.out.print("Amount: ");
                    w.withdraw(sc.nextDouble());
                    break;
                case 3:
                    System.out.println("Balance = " + w.balance);
                    break;
                case 4:
                    System.out.println("Thank you");
                    break;
                default:
                    System.out.println("Invalid choice, try again");
            }
        } while (ch != 4);
    }
}

ch is declared before the do so that the while condition can see it. Declared inside the loop, it would be out of scope and the program would not compile.

NameTypePurpose
balancedoubleinstance variable: money held in the wallet
amtdoubleparameter: amount to add or take out
wWalletthe object whose methods are called
chintmenu choice; 4 ends the loop
deposit, withdrawvoid methodsdo the work of options 1 and 2
Sample runJava 21
1. Deposit  2. Withdraw  3. Balance  4. Exit
Choice: 1
Amount: 500
Deposited. Balance = 500.0
1. Deposit  2. Withdraw  3. Balance  4. Exit
Choice: 2
Amount: 800
Not enough balance
1. Deposit  2. Withdraw  3. Balance  4. Exit
Choice: 2
Amount: 120
Withdrawn. Balance = 380.0
1. Deposit  2. Withdraw  3. Balance  4. Exit
Choice: 5
Invalid choice, try again
1. Deposit  2. Withdraw  3. Balance  4. Exit
Choice: 3
Balance = 380.0
1. Deposit  2. Withdraw  3. Balance  4. Exit
Choice: 4
Thank you

Choice 5 reaches default and the loop simply offers the menu again. The withdraw method guards against taking out more than the balance.

Single run or repeating? Read the question

If the question saysWrite
"Write a menu driven program to ..." with no mention of repeatingOne menu, one switch, no loop (Programs 1 to 3)
"... until the user chooses to exit" or "the menu should be displayed repeatedly"do-while around the menu and switch, with an exit case (Program 4)
"Using a switch case and user-defined methods ..."Each case calls a method; the method does the work and prints or returns the result

Methods that return values to a switch, and how to overload them, are covered on user-defined methods and overloading for ICSE Class 10. Bill programs that use a slab ladder instead of a menu are on slab and bill programs for ICSE.

Q4. What do switch case questions in Section A ask?

Switch case questions ICSE: fall-through, stacked labels, conversions and errors

Short switch questions test four things: what a fragment prints when a break is missing, how to convert an if-else ladder into a switch, which selector types are allowed, and which case labels will not compile. Try each before opening the answer.

  1. Rewrite with switch: marks m (0 to 100) give grade A for 90 and above, B for 70 to 89, C for 60 to 69 and D below 60.

    Answerswitch on m / 10
    int m = 74;
    char g;
    switch (m / 10) {
        case 10:
        case 9: g = 'A'; break;
        case 8:
        case 7: g = 'B'; break;
        case 6: g = 'C'; break;
        default: g = 'D';
    }
    System.out.println(g);
    
    // Output: B

    switch cannot test a range, so divide by 10 to turn each band into one value. 100 / 10 is 10, so case 10 is stacked on case 9.

  2. Predict the output.

    Missing breakfall-through
    int x = 3;
    switch (x) {
        case 3: x += 2;
        case 4: x *= 2; break;
        case 5: x = 0;
    }
    System.out.println(x);
    
    // Output: 10

    Control enters at case 3 (x becomes 5), has no break, so falls into case 4 (x becomes 10) and stops at that break. The new value of x does not send control to case 5: the case is chosen only once, at the top.

  3. Predict the output. The default label does not have to come last.

    default firstno matching case
    int k = 7;
    switch (k % 3) {
        default: System.out.print("D");
        case 0: System.out.print("Z"); break;
        case 2: System.out.print("T");
    }
    
    // Output: DZ

    7 % 3 is 1, which has no case, so control goes to default, prints D, falls into case 0, prints Z and breaks.

  4. Can a switch work on a String? Yes. Since Java 7 the selector can be a String, compared with equals behind the scenes.

    String selectorJava 7 and later
    String op = "MUL";
    switch (op) {
        case "ADD": System.out.println(6 + 3); break;
        case "MUL": System.out.println(6 * 3); break;
        default: System.out.println("?");
    }
    
    // Output: 18

Three switch statements that do not compile

Fragmentjavac 21 saysThe rule
double d = 2.0; switch (d) { case 2.0: ... }selector type double is not allowedWith constant case labels, as in every ICSE switch, the selector may be byte, short, char, int, their wrappers, String or an enum; never double, float, long or boolean
case 1: ... break; case 1: ...duplicate case labelEach case value may appear only once in a switch
int k = 1; ... case k: ...constant expression requiredA case label must be a constant or a literal, not a variable

switch or if-else: the comparison asked for two marks

switchif-else ladder
Tests one expression for equality with fixed valuesCan test any condition, including ranges and several variables
Works with int, char, String and similar types onlyWorks with any type, double and boolean included
Needs break to stop fall-through into the next caseRuns only the first true branch; no break needed
Natural fit for a menu of numbered or lettered choicesNatural fit for slabs, bands and compound conditions

More fragments like these, sorted by trap, are on ICSE Computer Applications output questions, and compile errors of every kind are practised on ICSE Class 10 Java error finding questions.

Q5. How are menu programs drilled in the live class?

Template first, then every choice tested: a menu lesson in the mini batch

The five-part template is learnt in the first lesson and then reused in every menu afterwards, so the class time goes on the logic inside each case and on testing.

Template from memory

At the start of the Tuesday 5:30 PM IST class, students write the empty menu skeleton from memory in under two minutes: menu lines, choice, cases, breaks, default.

Fill each case

The teacher sets a two- or three-option question in board wording. Each case is then planned as its own small program, with its own input and output.

Test every path

At the Wednesday 8:00 PM IST class the programs are run in BlueJ with one input per option and one wrong choice, so a missing default or break shows up on screen.

Marked like the board

Hand-written answers are marked against a scheme with the class watching: logic, syntax, the default message, comments and the variable table.

Switch questions in rotation

Short fall-through, conversion and error questions return in the weekly Section A set so they stay fresh until the exam.

Menus inside mock papers

From December, menu questions appear in full two-hour mock papers alongside the other Section B families.

The full list of Section B program families, with links to each, is on ICSE Class 10 Java programs for practice.

Batch or personalised: you choose

Write menu programs in the mini batch, or one to one

The template, the test-every-path habit and the BlueJ checks are the same in both formats. In India, families choose the fixed evening mini batch or a private slot; ICSE students abroad are taught one to one. Billing is monthly, with no admission fee.

Option 1 · Fixed batch timings

Mini batch, Tuesday 5:30 PM and Wednesday 8 PM

₹2,999

per month, two live classes a week

  • Tuesday 5:30 PM and Wednesday 8:00 PM IST, live
  • Up to six ICSE Class 10 students per batch
  • A menu question in board wording most weeks
  • Every option and one wrong choice run in BlueJ
  • Answers marked against a scheme on screen
Book a free demo in this batch

Option 2 · Choose your own timing

Personalised one to one

₹4,999

per month, one private class a week, at a time set with you

  • A slot that suits the family, in India or abroad
  • Focus on what your child misses: break, default or the logic inside
  • Menus built around the school's own worksheets
  • Repeating menus with methods and objects once basics are firm
  • The teachers and 2027 syllabus of the batch, taught privately
Ask for a personalised plan

If your child writes correct logic but keeps losing marks for a missing break or a forgotten default, a few one to one sessions on the template usually settle it. If menus are one of several Section B families still to practise, the twice-weekly batch covers them all in turn. The fee for each format appears in your local currency.

Studying outside India?

Menu driven program practice for ICSE students abroad

ICSE schools overseas write the same Computer Applications paper, so the same switch menus and the same default case decide marks there too. Outside India the lessons are one to one, at an early evening time in the student's own zone.

Where you liveTime differenceUsual class window, local timeFormat
India (IST)
every Indian city
ISTTue 5:30 PM, Wed 8:00 PMMini batch or 1-on-1
United Arab Emirates
Dubai, Sharjah
1 h 30 min behind India3:00 PM to 9:00 PMPersonalised 1-on-1
Indonesia and Thailand
West Java, Bangkok area
1 h 30 min ahead of India3:30 PM to 9:00 PMPersonalised 1-on-1
Singapore
Singapore
2 h 30 min ahead of India3:30 PM to 9:00 PMPersonalised 1-on-1

The time is agreed after the free demo and can be moved around school exams. How the overseas lessons are arranged is explained on ICSE Computer Applications classes in the Gulf and abroad.

What families say

Rated 4.9 across 547 Google reviews

Real reviews from real families. We neither write nor commission them.

★★★★★

"The one step solution for my son. Modern Age Coders make learning coding so simple that kids love it. The teachers explain complex concepts clearly with practical exercises and interactive content."

Ria Mukherjee

Parent

★★★★★

"Modern Age Coders has been a game-changer for me. I struggled to grasp IT concepts and coding before joining, but their classes transformed everything. I can now confidently write complex programs with ease."

Samriddha Mondal

Student

★★★★★

"One of the most wonderful education centres out there. Education is not limited to school syllabus but focuses on skill development."

Vansh Agarwal

Student

★★★★★

"My child Dhairya is really enjoying the Modern Age Coders classes. This is his first online class and he eagerly looks forward to it. I can already see his improvement, and the teachers are very cooperative."

Sonam Oswal

Parent of Dhairya

★★★★★

"Modern Age Coders have wonderful teachers who teach in a clear, easy and practical way. The teacher boosts students' confidence and inspires them to learn without hesitation."

Sonu Goyal

Parent

★★★★★

"I highly recommend this computer coding class! The teachers are incredibly knowledgeable and passionate about coding."

Ritu Kedia

Parent

The rest of the Class 10 series

More pages for Class 10 board students

Every page in the ICSE Class 10 Computer Applications series, grouped by what you need: classes, each chapter, Section B programs, question practice, notes and revision, and the exam itself.

CBSE Class 10 AI (417): The Mon and Wed 9 PM AI batch CBSE AI 417 syllabus explained CBSE AI important questions Sample paper and mock tests

Questions about menu programs

What students ask about menu driven programs and switch case

What is a menu driven program in Java?

It is a program that shows the user a list of options, reads which option they want, and then runs only the code for that option. In ICSE Class 10 the choice is read with Scanner and the branching is done with a switch statement, with a default case for a choice that is not on the list.

How do you write a menu driven program using switch case in Java?

Print the menu with one println per option, read the choice into an int or char, then write switch (choice) with one case per option. Put the full logic for each option inside its case and end it with break. Finish with a default case that prints a message such as "Invalid choice".

Why is the default case important in a menu driven program?

ICSE questions usually ask for an appropriate message when the user enters a wrong choice, and the default case is where that message goes. Leaving it out means a wrong choice silently does nothing, and the answer misses part of what the question asked.

What happens if break is missing in a switch case?

Control falls through into the next case and runs its statements too, until it meets a break or the end of the switch. The case is chosen only once, at the top, so changing the variable inside a case does not redirect control. Stacking labels such as case 'A': case 'a': uses fall-through on purpose.

Can we use a char in a switch statement in Java?

Yes. Read the choice with sc.next().charAt(0) and write each label in single quotes, such as case 'G':. To accept both capital and small letters, stack two labels on the same block of code.

Can switch case be used with double or boolean in Java?

No. In the switch with constant case labels that ICSE uses, the selector may be byte, short, char, int, their wrapper classes, a String or an enum. A double, float, long or boolean selector does not compile, so use an if-else ladder for those.

What is the difference between switch case and if-else in Java?

switch compares one expression with fixed constant values and needs break to stop fall-through. if-else can test any condition, including ranges and several variables, and runs only the first true branch. Menus suit switch; slabs and ranges suit if-else.

How do you repeat a menu until the user chooses exit?

Put the menu and the switch inside a do-while loop and declare the choice variable before the loop. Add an exit option, for example case 4, and end the loop with while (choice != 4). do-while suits a menu because it must be shown at least once.

Are menu driven programs asked in the ICSE Class 10 board exam?

Menu and switch case questions are a regular Section B shape, often pairing a pattern with a series or two calculations. Switch also appears in Section A as output and conversion questions. Practising the five-part template prepares a student for both.

Do you teach menu driven programs in live classes?

Yes. In the ICSE mini batch students write menus to the five-part template by hand, then run every option and one wrong choice in BlueJ on a shared screen. Students who need more time can take personalised one to one classes at a time the family chooses.

Start

Try a free live menu driven programs class

In the free demo your child writes the menu skeleton with the mentor, fills in two options from a board-style question, and runs every choice in BlueJ, a wrong one included. Afterwards you hear plainly what is secure and what needs work, and whether the mini batch or one to one fits better.

Prefer to see the whole subject first? Visit ICSE Computer Applications important questions or the ICSE Class 10 Java classes.

WhatsApp us · +91 91233 66161 · connect@modernagecoders.com

Every class is live video. The form requests a callback and reserves nothing.

We call within a few hours. No card, no enrolment fee.

Want it sooner? Book a priority demo

A full live class of about 45 to 60 minutes at a slot you pick, with a written skill report and learning roadmap on WhatsApp afterwards. The fee is adjusted against your first month if you enrol.

Book a priority demo

Keep exploring Modern Age Coders

By class and age

Learn more

Free resources

From the blog

Start here