Skip to content
Computer ApplicationsICSE Class 9 · Chapter 8

Conditional Statements in Java ICSE Class 9: if, if-else, Ladder, Nested if and switch

Updated 15 October 2026 · Fact-checked

Conditional statements let a Java program choose which statements to run depending on a condition. ICSE Class 9 tests if, if-else, the if-else-if ladder, nested if, and switch-case with default and break, including fall through when break is missing, menu-driven programs and System.exit(0) to end a program.

What Conditional Statements in Java is about

Most real programs make decisions: pass or fail, which electricity slab applies, which menu option was chosen. Java makes these decisions with conditional (decision-making) statements. Questions test both writing them and tracing them, especially the effect of a missing break in switch and which if an else belongs to.

The CISCE syllabus asks for decision making using if, if else, if else if ladder, switch-case, default and break, with programs on if, if else, if else if, nested if, switch case, the break statement, the fall-through condition in switch case, menu-driven programs, and System.exit(0) to terminate the program.

In programs, test every branch with a value: below, on and above each boundary. Most lost marks come from boundary values (< instead of <=).

Weightage: CISCE publishes no chapter weightage and no question-paper layout for ICSE Class 9 Computer Applications. Class IX is examined by your school: one 100-mark theory paper of 2 hours, plus 100 marks of internal assessment (at least 15 programming assignments and a written project on ethical computing). This is topic 8 of the 2028 syllabus.Source: CISCE ICSE 2028 Computer Applications syllabus, Class IX

Key concepts

if and if-else

if statement: runs a statement (or block) only when the condition is true.
if (condition)
{
statements;
}

if-else statement: chooses between two alternatives.
if (condition)
statement1; // when true
else
statement2; // when false

Rules:

  • The condition must be a boolean expression in brackets: (marks >= 40). Writing if (x = 5) is a compile-time error in Java (int cannot be converted to boolean); use ==.
  • Without braces, only the first statement after if (or else) belongs to it. Use braces { } for more than one statement.
  • No semicolon straight after if (condition): if (a > b); makes an empty statement, and the next line always runs.

Example (as run in this study guide): int x = 7; if (x % 2 == 0) System.out.println("Even"); else System.out.println("Odd"); prints Odd.

Braces trap (as run): int m = 10; if (m > 5) m = m + 1; m = m * 2; gives 22: only m = m + 1 is controlled by if; m = m * 2 always runs.

Worked example

(2 marks) Give the output: int m = 4; if (m > 5) m = m + 1; m = m * 2; System.out.println(m);

Try it first, then show the solutionSolution
  1. Without braces, only m = m + 1 belongs to the if; 4 > 5 is false, so it is skipped - 1 mark.
  2. m = m * 2 always runs: 8 - 1 mark.

Answer: 8

The if-else-if ladder

Used when one of several conditions must be chosen. Conditions are tested from the top; the first true one runs and the rest are skipped. The final else runs if none is true.

if (cond1) s1;
else if (cond2) s2;
else if (cond3) s3;
else s4;

Slab billing example (hypothetical tariff, as run in this study guide):
Units up to 100: Rs 5.00 per unit; next 100: Rs 6.50; next 100: Rs 8.00; above 300: Rs 10.00.
if (u <= 100)
amt = u * 5.0;
else if (u <= 200)
amt = 100 * 5.0 + (u - 100) * 6.5;
else if (u <= 300)
amt = 100 * 5.0 + 100 * 6.5 + (u - 200) * 8.0;
else
amt = 100 * 5.0 + 100 * 6.5 + 100 * 8.0 + (u - 300) * 10.0;
Results: 80 units → Rs 400.0; 250 units → Rs 1550.0; 340 units → Rs 2350.0.

Because the ladder stops at the first true condition, the second test need not repeat u > 100.

Worked example

(2 marks) Using the slab tariff above, calculate the bill for 250 units, showing the slabs.

Try it first, then show the solutionSolution
  1. First 100 × 5.00 = 500; next 100 × 6.50 = 650 - 1 mark.
  2. Remaining 50 × 8.00 = 400; total = 1550 - 1 mark.

Answer: Rs 1550.0

Nested if and the dangling else

A nested if is an if (or if-else) inside another if or else. It is used when a second decision depends on the first.

Largest of three (as run in this study guide with p = 15, q = 25, r = 20):
if (p > q)
{
if (p > r) big = p; else big = r;
}
else
{
if (q > r) big = q; else big = r;
}
Output: Largest = 25

Dangling else rule: an else belongs to the nearest unmatched if above it, whatever the indentation.
int a = 5, b = 10;
if (a > b)
if (a > 0)
System.out.println("A");
else
System.out.println("B");
System.out.println("C");
The else pairs with if (a > 0). Since a > b is false, the whole inner if-else is skipped, and only C is printed (as run).
Use braces to make the intended pairing clear.

Worked example

(2 marks) In the dangling-else code above, what is printed if a = 15 and b = 10?

Try it first, then show the solutionSolution
  1. a > b is true, so the inner if-else runs - 1 mark.
  2. a > 0 is true: prints A; then C is printed (outside the if) - 1 mark.

Answer: A
C

switch-case, break and default

switch selects one of many branches by comparing a single value with constant case labels.
switch (expression)
{
case value1: statements; break;
case value2: statements; break;
default: statements;
}

Rules:

  • The expression may be of type int, char, short, byte (or String); not double, float, long or boolean.
  • Case labels must be constants (literals), not ranges or conditions, and must not repeat.
  • break ends the switch; control passes to the statement after it.
  • default runs when no case matches; it is optional and may be placed anywhere, though usually last.
  • Several cases can share statements: case 'a': case 'e': case 'i': case 'o': case 'u': System.out.println("Vowel"); break;

switch vs if-else-if:
1. switch tests only equality with constants; if can test any condition (ranges, &&, ||).
2. switch works on int, char, String (and smaller integer types); if works with any boolean expression.
3. switch is neater for menus with many fixed choices.

Worked example

(2 marks) State two differences between switch-case and the if-else-if ladder.

Try it first, then show the solutionSolution
  1. switch checks equality with constant values only; if can test ranges and logical conditions - 1 mark.
  2. switch works only with int, char, String, byte, short; if works with any boolean expression including double comparisons - 1 mark.

Answer: (1) switch compares one value for equality with constant case labels, whereas if-else-if can test any condition, such as ranges and combined conditions. (2) switch accepts only integer types, char and String, whereas if works with any boolean expression, including those on double values.

Fall through

If a case has no break, control 'falls through' into the following case(s) and runs their statements too, until a break or the end of the switch.

As run in this study guide:
switch (n)
{
case 1: System.out.print("One ");
case 2: System.out.print("Two ");
case 3: System.out.print("Three ");
break;
case 4: System.out.print("Four ");
default: System.out.print("Other ");
}
n = 2 prints: Two Three
n = 4 prints: Four Other

Fall through is useful when several cases share an action (vowels), but a forgotten break is a common logical error.

Worked example

(2 marks) Using the switch above, what is printed for n = 1 and for n = 7?

Try it first, then show the solutionSolution
  1. n = 1: One, falls to Two and Three, then break - 1 mark.
  2. n = 7: no case matches; default prints Other - 1 mark.

Answer: n = 1: One Two Three
n = 7: Other

Menu-driven programs and System.exit(0)

A menu-driven program displays a list of choices, accepts the user's choice and performs the matching task, usually with switch.

System.exit(0) terminates the program immediately; no further statements run. The argument 0 indicates normal termination (a non-zero value signals an abnormal end).

Program (as run in this study guide):
import java.util.*;
class Menu
{
public static void main(String args[])
{
Scanner sc = new Scanner(System.in);
System.out.println("1. Area of a circle");
System.out.println("2. Area of a square");
System.out.println("3. Exit");
System.out.print("Enter your choice: ");
int ch = sc.nextInt();
switch (ch)
{
case 1:
System.out.print("Radius: ");
double r = sc.nextDouble();
System.out.println("Area = " + Math.round(Math.PI * r * r * 100) / 100.0);
break;
case 2:
System.out.print("Side: ");
double s = sc.nextDouble();
System.out.println("Area = " + s * s);
break;
case 3:
System.out.println("Goodbye");
System.exit(0);
default:
System.out.println("Invalid choice");
}
System.out.println("End of menu");
}
}
Runs: choice 1, radius 7 → Area = 153.94 then End of menu; choice 3 → Goodbye only (System.exit(0) stops the program, so neither default nor End of menu runs); choice 5 → Invalid choice, End of menu.
(Math.PI is the constant π stored in the Math class.)

Worked example

(2 marks) In the Menu program, case 3 has no break. Why does 'Invalid choice' not appear when 3 is entered?

Try it first, then show the solutionSolution
  1. System.exit(0) ends the program at once - 1 mark.
  2. So control never falls through to default or reaches 'End of menu' - 1 mark.

Answer: System.exit(0) terminates the whole program immediately, so execution never falls through into default and the final println is never reached; only Goodbye is printed.

Conditional Statements in Java in real life

Each concept, met in an everyday situation. Read the situation, answer the question in your own words, then compare with the model answer. The one-line hook is what to remember.

if-else-if ladder

Suppose a cinema charges Rs 100 for children under 12, Rs 200 for people aged 12 to 59 and Rs 120 for those 60 and over.

Write the ladder and find the price for ages 12 and 60.

Try it first, then show the solutionSolution
  1. if (age < 12) price = 100;
  2. else if (age < 60) price = 200;
  3. else price = 120; Age 12 → 200 (not under 12); age 60 → 120.

Answer: if (age < 12) price = 100; else if (age < 60) price = 200; else price = 120; Age 12 pays Rs 200 and age 60 pays Rs 120.

Memory hook: Test the boundaries: 11, 12, 59, 60.

Menu with switch

Imagine a bank's phone helpline: 'Press 1 for balance, 2 for last five transactions, 3 to talk to an officer, 9 to end the call.'

Which Java construct models this, and what models 'end the call'?

Try it first, then show the solutionSolution
  1. One fixed number chooses one action: switch-case.
  2. Each option is a case with break.
  3. Ending the call corresponds to System.exit(0); an invalid key goes to default.

Answer: A menu-driven switch: case 1, case 2, case 3 for the options, default for invalid keys, and System.exit(0) for ending the program.

Memory hook: Fixed choices: switch; wrong key: default.

Fall through

Suppose a gym offers plans: Gold includes sauna, pool and gym; Silver includes pool and gym; Basic includes gym only.

How can fall through list the facilities of a plan neatly?

Try it first, then show the solutionSolution
  1. Order cases from the richest plan down: case 'G': print sauna; case 'S': print pool; case 'B': print gym; break;
  2. Gold falls through all three; Silver falls through pool and gym.
  3. Only one break at the end is needed.

Answer: With case 'G' printing sauna, case 'S' pool and case 'B' gym, and a break only after gym, choosing G prints all three, S prints pool and gym, and B prints gym: deliberate fall through.

Memory hook: No break, keep going.

Topics in this chapter

Conditional Statements in Java: syntax and key facts

if forms
if; if-else; if-else-if ladder; nested if
else pairs with the nearest unmatched if.
switch
switch (int/char/String) { case const: ...; break; default: ... }
No double, long or boolean; constants only.
Fall through
Missing break → next case's statements also run
Until break or end.
Exit
System.exit(0) → terminate the program normally
Nothing after it runs.
Leap year
(y % 4 == 0 && y % 100 != 0) || y % 400 == 0
2000 leap, 1900 not.

How the school exam asks Conditional Statements in Java

The question patterns to expect, and the method that works for each.

Question typeHow it is askedMethod
MCQ and assertion-reason (1 mark)Which data type cannot be used in switch; role of break or default; what System.exit(0) does.switch: int, char, String; break ends switch; default for no match.
Output (2 marks)Trace switch with missing breaks; dangling else; if without braces.Follow control line by line; pair else with the nearest if.
Convert (2 marks)Rewrite switch as if-else or if-else as ternary.Each case becomes an == test joined by else if.
Program (15 marks)Slab billing, grading, menu-driven programs with switch and System.exit(0).Ladder for ranges; switch for menus; test boundaries.

Tricks to remember Conditional Statements in Java

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

  • Else hugs the nearest if

    An else always belongs to the closest if above that has no else.

    Use it when: Dangling else.

  • switch likes ICS

    Int, Char, String (and byte, short): never double, float, long or boolean.

    Use it when: switch data types.

  • Break the fall

    Without break, you fall into the next case.

    Use it when: Fall through.

Conditional Statements in Java: exam-level solved questions

Ordered from exam level to HOTS. Cover the solution, write your own, then compare step by step.

Example 1: switch data type · 1 mark · MCQExam level

Which of these cannot be the type of a switch expression?
(a) int
(b) char
(c) double
(d) String

Try it first, then show the solutionSolution
  1. switch accepts int, char, String, byte and short.
  2. double is not allowed.

Answer: (c) double

Example 2: Assertion and reason: if (x = 5) · 1 mark · Assertion-reasonHarder exam level

Assertion (A): if (x = 5) causes a compile-time error in Java when x is an int.
Reason (R): The condition of an if statement must be of boolean type.
(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

Try it first, then show the solutionSolution
  1. x = 5 is an assignment whose value is an int, not a boolean.
  2. The compiler reports 'int cannot be converted to boolean'; R explains A.

Answer: (a) Both A and R are true and R is the correct explanation of A

Example 3: Fall-through output · 2 marks · Short answerHarder exam level

Give the output for n = 2 and n = 4:
switch (n)
{
case 1: System.out.print("One ");
case 2: System.out.print("Two ");
case 3: System.out.print("Three ");
break;
case 4: System.out.print("Four ");
default: System.out.print("Other ");
}

Try it first, then show the solutionSolution
  1. n = 2: starts at case 2, falls into case 3, then break: Two Three.
  2. n = 4: case 4 has no break, falls into default: Four Other.

Answer: n = 2: Two Three
n = 4: Four Other

Example 4: Dangling else · 2 marks · Short answerHOTS / competency

Give the output:
int a = 5, b = 10;
if (a > b)
if (a > 0)
System.out.println("A");
else
System.out.println("B");
System.out.println("C");

Try it first, then show the solutionSolution
  1. The else belongs to if (a > 0), the nearest if.
  2. a > b is false, so the inner if-else is skipped entirely; only C prints.

Answer: C

Example 5: Convert switch to if · 2 marks · Very short answerExam level

Rewrite using if-else-if:
switch (d)
{
case 1: System.out.println("Mon"); break;
case 2: System.out.println("Tue"); break;
default: System.out.println("Other");
}

Try it first, then show the solutionSolution
  1. Each case becomes an equality test.
  2. default becomes the final else.

Answer: if (d == 1)
System.out.println("Mon");
else if (d == 2)
System.out.println("Tue");
else
System.out.println("Other");

Example 6: Leap year condition · 2 marks · Very short answerHarder exam level

Write a single condition for a leap year and state the results for 2024, 1900, 2000 and 2027.

Try it first, then show the solutionSolution
  1. Divisible by 4 but not by 100, or divisible by 400.
  2. (y % 4 == 0 && y % 100 != 0) || y % 400 == 0: 2024 true, 1900 false, 2000 true, 2027 false.

Answer: (y % 4 == 0 && y % 100 != 0) || y % 400 == 0. 2024: true; 1900: false; 2000: true; 2027: false.

Example 7: Electricity bill program · 15 marks · Long answerHarder exam level

Write a program to accept the units consumed and print the bill using this tariff: up to 100 units Rs 5.00 per unit; next 100 units Rs 6.50 per unit; next 100 units Rs 8.00 per unit; above 300 units Rs 10.00 per unit.

Try it first, then show the solutionSolution
  1. import java.util.*;
    class Bill8
    {
    public static void main(String args[])
    {
    Scanner sc = new Scanner(System.in);
    System.out.print("Units consumed: ");
    int u = sc.nextInt();
    double amt;
  2. if (u <= 100)
    amt = u * 5.0;
    else if (u <= 200)
    amt = 100 * 5.0 + (u - 100) * 6.5;
  3. else if (u <= 300)
    amt = 100 * 5.0 + 100 * 6.5 + (u - 200) * 8.0;
    else
    amt = 100 * 5.0 + 100 * 6.5 + 100 * 8.0 + (u - 300) * 10.0;
  4. System.out.println("Amount payable: Rs " + amt);
    }
    }
  5. Each slab charges only the units within it. Check: 340 units = 500 + 650 + 800 + 40 × 10 = 2350.

Answer: Sample runs (as run):
Units consumed: 250
Amount payable: Rs 1550.0
Units consumed: 340
Amount payable: Rs 2350.0

Case-study practice (Section B style)

Read the situation, then answer every part. In a school exam set on the board pattern this is a 7-mark question split into 2 + 3 + 2 marks.

A grading program

Imagine a school grades marks (0-100) as: 90 and above A; 75-89 B; 60-74 C; 40-59 D; below 40 E. Riya writes:
if (m >= 40) g = 'D';
else if (m >= 60) g = 'C';
else if (m >= 75) g = 'B';
else if (m >= 90) g = 'A';
else g = 'E';

  1. (i) · 2 marks

    What grade does Riya's code give for 95 marks? Explain the error.

    Answer

    Answer: D. The ladder stops at the first true condition; 95 >= 40 is true first, so the higher grades are never reached.

    1 mark output, 1 mark reason.

  2. (ii) · 3 marks

    Rewrite the ladder correctly.

    Answer

    Answer: if (m >= 90) g = 'A';
    else if (m >= 75) g = 'B';
    else if (m >= 60) g = 'C';
    else if (m >= 40) g = 'D';
    else g = 'E';

    Order from highest to lowest 2 marks; correct boundaries 1 mark.

  3. (iii) · 2 marks

    Why can this grading not be written directly with switch on m? Suggest how switch could be used.

    Answer

    Answer: Case labels must be single constant values, so a range such as 75-89 cannot be written as a case. The grade boundaries (90, 75, 60, 40) do not all fall on multiples of 10, so even switching on m / 10 would need extra if tests; an if-else-if ladder is the right construct for ranges.

    1 mark constants only, 1 mark why ranges suit if-else-if.

Where the marks are

How a typical answer is split into step marks. Show every step: a right final answer alone rarely earns full marks.

Give the output of a switch with a missing break (n = 2). (2 marks) (2 marks)

StepMarks
Correct starting case and recognition of fall through.1
Correct output up to the break: Two Three.1

Program: slab electricity bill with an if-else-if ladder. (15 marks) (15 marks)

StepMarks
import, class, main(), Scanner input of units.3
Correct ladder conditions in order with correct boundaries.4
Correct slab-wise amount in each branch.5
Output with label.3

Where students lose marks in Conditional Statements in Java

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

  • Mistake: Ladder in the wrong order

    Lowest condition written first.

    Wrong working

    if (m >= 40) ... else if (m >= 90) ...

    Right working

    if (m >= 90) ... else if (m >= 75) ... else if (m >= 40) ...

    Do this: With >=, test the highest value first.

    Usually costs: 2 to 4 marks.

  • Mistake: Missing break in switch

    Forgetting fall through.

    Do this: End every case with break unless fall through is intended.

    Usually costs: 1 to 3 marks.

  • Mistake: Using = instead of ==

    Mathematical habit.

    Wrong working

    if (x = 5)

    Right working

    if (x == 5)

    Do this: == compares; = assigns.

    Usually costs: 1 mark.

  • Mistake: Ranges in case labels

    Treating switch like if.

    Wrong working

    case m >= 90:

    Right working

    Use if-else-if for ranges.

    Do this: Case labels must be constants.

    Usually costs: 1 to 2 marks.

  • Mistake: Missing braces around several statements

    Indentation is trusted.

    Do this: Put { } round every block of more than one statement.

    Usually costs: 1 to 2 marks.

Practice questions on Conditional Statements in Java

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 · MCQExam level

    Which statement is used to terminate a Java program immediately?
    (a) break;
    (b) System.exit(0);
    (c) return 0;
    (d) default;

    Hint

    Whole program.

    Answer

    (b) System.exit(0);

  2. Q2 · 1 mark · MCQExam level

    In a switch, the default case runs when:
    (a) always
    (b) the first case matches
    (c) no case matches
    (d) break is missing

    Hint

    Fallback.

    Answer

    (c) no case matches

  3. Q3 · 2 marks · Very short answerHarder exam level

    Give the output: char c = 'e'; switch (c) { case 'a': case 'e': case 'i': case 'o': case 'u': System.out.println("Vowel"); break; default: System.out.println("Consonant"); }

    Hint

    Shared cases.

    Answer

    Vowel

  4. Q4 · 2 marks · Short answerHOTS / competency

    Find the error: if (marks >= 40); System.out.println("Pass"); What happens when marks = 25?

    Hint

    Semicolon after the condition.

    Answer

    The semicolon after the condition ends the if with an empty statement, so println("Pass") is not controlled by the if. For marks = 25 it still prints Pass (a logical error).

  5. Q5 · 2 marks · Very short answerExam level

    Rewrite using the ternary operator: if (n % 2 == 0) s = "Even"; else s = "Odd";

    Hint

    ?:

    Answer

    s = (n % 2 == 0) ? "Even" : "Odd";

  6. Q6 · 2 marks · Very short answerHarder exam level

    Write a nested if to print the largest of three numbers p, q, r. What is printed for p = 15, q = 25, r = 20?

    Hint

    Compare p and q first.

    Answer

    if (p > q) { if (p > r) big = p; else big = r; } else { if (q > r) big = q; else big = r; } System.out.println("Largest = " + big); Output: Largest = 25

  7. Q7 · 15 marks · Long answerHarder exam level

    Write a menu-driven program: 1 for the area of a circle (radius input, rounded to 2 decimal places), 2 for the area of a square (side input), 3 to exit using System.exit(0); print 'Invalid choice' otherwise.

    Hint

    switch with break; default.

    Answer

    import java.util.*;
    class Menu
    {
    public static void main(String args[])
    {
    Scanner sc = new Scanner(System.in);
    System.out.println("1. Area of a circle");
    System.out.println("2. Area of a square");
    System.out.println("3. Exit");
    System.out.print("Enter your choice: ");
    int ch = sc.nextInt();
    switch (ch)
    {
    case 1:
    System.out.print("Radius: ");
    double r = sc.nextDouble();
    System.out.println("Area = " + Math.round(Math.PI * r * r * 100) / 100.0);
    break;
    case 2:
    System.out.print("Side: ");
    double s = sc.nextDouble();
    System.out.println("Area = " + s * s);
    break;
    case 3:
    System.out.println("Goodbye");
    System.exit(0);
    default:
    System.out.println("Invalid choice");
    }
    System.out.println("End of menu");
    }
    }
    Sample runs (as run): choice 1 with radius 7 prints Area = 153.94 and End of menu; choice 3 prints Goodbye only; choice 5 prints Invalid choice and End of menu.

  8. Q8 · 2 marks · Very short answerHarder exam level

    A shop gives a 10% discount on bills over Rs 5,000 and 5% on bills over Rs 2,000 (and up to 5,000). Write the if-else-if statements to compute the net amount for bill b.

    Hint

    Larger threshold first.

    Answer

    if (b > 5000) net = b - b * 10 / 100.0;
    else if (b > 2000) net = b - b * 5 / 100.0;
    else net = b;

  9. Q9 · 2 marks · Short answerHOTS / competency

    Why is it a good idea always to include a default case in a menu-driven switch?

    Hint

    Unexpected input.

    Answer

    Users may type a choice that is not on the menu. Without default the program silently does nothing; with default it can tell the user 'Invalid choice', making the program clear and robust.

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.Which if does an else belong to?Show answer

    The nearest unmatched if above it.

  2. 2.What does break do in switch?Show answer

    Exits the switch.

  3. 3.What happens without break?Show answer

    Fall through into the next case.

  4. 4.What does System.exit(0) do?Show answer

    Terminates the program normally.

  5. 5.Can switch use a double?Show answer

    No.

Best order to study it

  1. Learn if and if-else with braces and the semicolon trap.
  2. Learn the if-else-if ladder and practise slab and grade programs.
  3. Learn nested if and the dangling else rule.
  4. Learn switch, break, default and fall through.
  5. Write menu-driven programs with System.exit(0).

Quick revision checklist

The night before the exam: can you do each of these without looking?

  • if (boolean) { }; else pairs with the nearest if.
  • Ladder: first true condition runs; order the conditions carefully.
  • switch: int, char, String, byte, short; constant cases; break; default.
  • No break → fall through.
  • System.exit(0) ends the program at once.
  • Ranges or complex conditions → if; fixed choices → switch.

Conditional Statements in Java: frequently asked questions

Can the default case come first?

Yes, default can be placed anywhere in the switch, but it runs only when no case matches. Placing it last is clearer; if it is not last, give it a break.

Can I use String in switch?

Yes, Java allows String in switch (for example case "red":). Most ICSE menu programs use int or char.

Is the ternary operator a conditional statement?

It is a conditional operator that chooses between two values in an expression; it is useful for short if-else choices such as max = (a > b) ? a : b;

Based on: CISCE ICSE 2028 Computer Applications (86) syllabus (Classes IX and X); CISCE Regulations for ICSE Examination Year 2028