Skip to content
Computer ApplicationsICSE Class 10 · Chapter 7

Conditional Constructs in Java ICSE Class 10 Computer Applications

Updated 14 October 2026 · Fact-checked

Conditional constructs let a Java program choose what to do. if runs a block when a condition is true; if-else chooses between two blocks; an if-else-if ladder tests conditions in turn; nested if puts one if inside another; and switch-case picks a case by matching a value, with break preventing fall through and default handling no match.

What Conditional Constructs in Java is about

Every slab-based bill, grade or menu program in Section B depends on conditions. The 2024 paper asked which data type cannot be used with switch (double) and the largest of a, b, c from if (a > b && b > c); the 2025 paper had an assertion-reason on break and fall through. In the 2024 courier program and the 2025 cloud-storage program, examiners deducted marks for wrong slab calculations and wrong relational operators.

The syllabus asks for if, if-else, if-else-if, nested if, switch-case, default and break, the fall-through condition in switch, menu-driven programs, and System.exit(0) to terminate a program.

Weightage: CISCE publishes no chapter weightage. Section A (40 marks) is compulsory: 1-mark MCQs and 2-mark short answers including output and error questions; in Section B you answer any four of six 15-mark programming questions written in Java.Source: CISCE ICSE Computer Applications (661) specimen paper structure for 2027

Key concepts

if and if-else

if statement: executes a statement or block only when the condition is true.
if (marks >= 40)
System.out.println("Pass");

if-else: executes one block when the condition is true and another when it is false.
if (n % 2 == 0)
System.out.println("Even");
else
System.out.println("Odd");

The condition must give a boolean (true/false). Without braces { }, only the next single statement belongs to the if or else; use braces when there is more than one statement. A semicolon right after if (...) ends the if: if (x > 0); makes the next statement run always.

Worked example

(2 marks) int x = -5; Give the output:
if (x > 0);
System.out.println("Positive");
System.out.println("Done");

Try it first, then show the solutionSolution
  1. The semicolon after if (x > 0) is an empty statement; the if controls nothing - 1 mark.
  2. Both println statements run regardless of x - 1 mark.

Answer: Positive
Done

if-else-if ladder and nested if

if-else-if ladder: tests several conditions in order; the first true condition's block runs and the rest are skipped; the final else (optional) runs if none is true. Ideal for slabs and grades:
if (m >= 90) grade = 'A';
else if (m >= 75) grade = 'B';
else if (m >= 60) grade = 'C';
else grade = 'D';

Nested if: an if inside another if, used when a second test depends on the first:
if (age >= 18)
{
if (hasID) System.out.println("Can vote");
else System.out.println("Bring ID");
}
else System.out.println("Too young");

An else always pairs with the nearest unmatched if above it, unless braces say otherwise.

Worked example

(2 marks) int x = 15; Give the output:
if (x > 10)
if (x > 20)
System.out.println("P");
else
System.out.println("Q");

Try it first, then show the solutionSolution
  1. The else pairs with the nearest if, i.e. if (x > 20) - 1 mark.
  2. x > 10 is true; x > 20 is false, so the else runs - 1 mark.

Answer: Q

switch-case, break, default and fall through

switch selects one of many cases by matching the value of an expression:
switch (choice)
{
case 1: System.out.println("Tea"); break;
case 2: System.out.println("Coffee"); break;
default: System.out.println("Invalid");
}

Rules: the switch expression may be int, char, String (and byte, short), but not double, float, long or boolean. Case labels must be constants and unique.
break ends the switch after a case runs.
default runs when no case matches (it is optional and may be anywhere).
Fall through: if a case has no break, execution continues into the following cases until a break or the end of the switch. It can be used on purpose to share code: case 'a': case 'e': case 'i': case 'o': case 'u': vowel++; break;

Worked example

(2 marks) int n = 2; Give the output:
switch (n)
{
case 1: System.out.print("A");
case 2: System.out.print("B");
case 3: System.out.print("C"); break;
default: System.out.print("D");
}

Try it first, then show the solutionSolution
  1. n matches case 2: B is printed; there is no break, so it falls through - 1 mark.
  2. case 3 prints C, then break stops; default is skipped - 1 mark.

Answer: BC

switch vs if-else-if, and System.exit(0)

Differences: (1) switch tests only equality with constant values; if can test any condition, including ranges (m >= 60). (2) switch works with int, char and String; if works with any boolean expression, including double comparisons. (3) switch is neater for menus with many fixed choices; if-else-if is needed for slabs and ranges.

System.exit(0) terminates the whole program at once (0 means normal termination). It is used in menu programs for an 'Exit' choice, or after a search is successful so that the 'not found' message is not printed.

Worked example

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

Try it first, then show the solutionSolution
  1. switch checks equality with constants only; if checks any condition, including ranges - 1 mark.
  2. switch cannot use double or boolean expressions; if can - 1 mark.

Answer: (1) switch-case tests a value for equality with constant case labels, while if-else-if can test any condition such as ranges. (2) switch works only with int, char, String (and byte, short), while if-else-if works with any boolean condition, including double values.

Menu-driven programs

A menu-driven program shows a list of options, accepts the user's choice and uses switch to perform the chosen task, with default for an invalid choice.

import java.util.Scanner;
class AreaMenu
{
public static void main(String args[])
{
Scanner sc = new Scanner(System.in);
System.out.println("1. Circle 2. Square 3. Rectangle");
System.out.print("Choice: ");
int ch = sc.nextInt();
switch (ch)
{
case 1:
System.out.print("Radius: ");
double r = sc.nextDouble();
System.out.println("Area = " + (3.14 * r * r));
break;
case 2:
System.out.print("Side: ");
double s = sc.nextDouble();
System.out.println("Area = " + (s * s));
break;
case 3:
System.out.print("Length and breadth: ");
double l = sc.nextDouble();
double b = sc.nextDouble();
System.out.println("Area = " + (l * b));
break;
default:
System.out.println("Wrong choice");
}
}
}

Sample runs: choice 2, side 5 → Area = 25.0. Choice 7 → Wrong choice.

Worked example

(2 marks) In the menu program above, what is printed for choice 3 with length 4 and breadth 2.5? What if break after case 2 were removed and choice 2 was entered?

Try it first, then show the solutionSolution
  1. Choice 3: 4 × 2.5 = 10.0, so Area = 10.0 - 1 mark.
  2. Without break, after the square's area the program would fall into case 3 and ask for length and breadth too - 1 mark.

Answer: Area = 10.0. Without the break, choice 2 would print the square's area and then fall through into case 3, also asking for length and breadth.

Conditional Constructs 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 for slabs

Suppose a mobile data plan charges ₹10 per GB for the first 5 GB, ₹8 per GB for the next 10 GB and ₹5 per GB beyond 15 GB.

Find the charge for 18 GB and write the slab logic.

Try it first, then show the solutionSolution
  1. First 5 GB: 5 × 10 = 50.
  2. Next 10 GB: 10 × 8 = 80.
  3. Remaining 3 GB: 3 × 5 = 15; total 145.
  4. Logic: if (g <= 5) c = g * 10; else if (g <= 15) c = 50 + (g - 5) * 8; else c = 50 + 80 + (g - 15) * 5;

Answer: ₹145, using an if-else-if ladder with each slab charged at its own rate.

Memory hook: Each slab pays its own rate; add the full slabs below.

switch for menus

Imagine a lift panel: pressing 0 to 4 sends the lift to that floor, and any other key shows 'Invalid'.

Which construct fits and why?

Try it first, then show the solutionSolution
  1. The input is one of a few fixed integer values.
  2. Each value has its own action.
  3. Other keys need a common response: default.

Answer: switch-case with cases 0 to 4 and a default for 'Invalid', because the choices are fixed constants.

Memory hook: Fixed buttons, use switch.

Nested if

Suppose a theme park ride allows children only if they are taller than 120 cm, and among them those under 140 cm must ride with an adult.

Write the nested if.

Try it first, then show the solutionSolution
  1. First test height > 120.
  2. Inside it, test height < 140 for the adult rule.
  3. Else outside: not allowed.

Answer: if (h > 120) { if (h < 140) System.out.println("Ride with adult"); else System.out.println("Ride alone"); } else System.out.println("Not allowed");

Memory hook: Ask the second question only after the first says yes.

Topics in this chapter

Conditional Constructs in Java: syntax and key facts

if-else syntax
if (condition) { … } else if (condition) { … } else { … }
else pairs with nearest unmatched if.
switch syntax
switch (expr) { case c1: …; break; case c2: …; break; default: …; }
expr: int, char, String, byte, short.
Slab formula
charge = (full lower slabs) + (units − slab start) × rate
e.g. 350 units: 100 × 2 + 200 × 3 + 50 × 5.
Exit
System.exit(0);
Ends the program immediately.

How the board asks Conditional Constructs in Java

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

Question typeHow it is askedMethod
MCQ and assertion-reason (Section A)Data type not allowed in switch (2024); largest number from if (a > b && b > c) (2024); break and fall through (2025).Remember allowed switch types; read compound conditions logically, not as code to compile.
Output (2 marks)Trace switch without break, nested if with dangling else, semicolon after if.Follow control flow line by line; mark where break or a semicolon ends a construct.
Program (15 marks)Slab-based bills (courier 2024, cloud storage 2025) and menu-driven programs.Use an if-else-if ladder with correct boundaries for slabs; switch with default for menus.

Tricks to remember Conditional Constructs in Java

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

  • No break, keep falling

    Without break, switch keeps falling into the next case like water down steps.

    Use it when: Fall-through outputs.

  • Switch says I-C-S

    Switch accepts Int, Char, String (and byte, short) - never double or boolean.

    Use it when: Switch data type MCQs.

Conditional Constructs in Java: board-level solved questions

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

Example 1: Switch data types · 1 mark · MCQBoard level

Which data type cannot be used in a switch expression?
(a) int
(b) char
(c) String
(d) double

Try it first, then show the solutionSolution
  1. switch works with int, char, String (and byte, short), not double.

Answer: (d) double

Example 2: Compound condition · 1 mark · MCQBoard level

If (a > b && b > c) is true, the largest number is:
(a) b
(b) c
(c) a
(d) wrong expression

Try it first, then show the solutionSolution
  1. a > b and b > c, so a > b > c.

Answer: (c) a

Example 3: Assertion and reason: break · 1 mark · Assertion-reasonHarder board level

Assertion (A): In switch-case, the break statement avoids fall through.
Reason (R): break makes only one case execute at a time.
(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. break exits the switch after the matching case, so control does not fall into the next case.

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

Example 4: Convert if-else-if to switch · 2 marks · Very short answerHarder board level

Rewrite using switch:
if (code == 'R') System.out.println("Red");
else if (code == 'G') System.out.println("Green");
else System.out.println("Unknown");

Try it first, then show the solutionSolution
  1. Each equality test becomes a case with break.
  2. The final else becomes default.

Answer: switch (code)
{
case 'R': System.out.println("Red"); break;
case 'G': System.out.println("Green"); break;
default: System.out.println("Unknown");
}

Example 5: Fall-through counting · 2 marks · Short answerHOTS / competency

Give the output:
int k = 3, s = 0;
switch (k)
{
case 3: s += 3;
case 4: s += 4; break;
case 5: s += 5;
}
System.out.println(s);

Try it first, then show the solutionSolution
  1. k = 3: s = 3; no break, falls to case 4: s = 7.
  2. break stops; case 5 is skipped.

Answer: 7

Example 6: Electricity bill (Section B) · 15 marks · Long answerHarder board level

Write a program to accept a consumer's name and units consumed and print the bill: first 100 units at ₹2 per unit, next 200 units at ₹3 per unit, and above 300 units at ₹5 per unit.

Try it first, then show the solutionSolution
  1. import java.util.Scanner;
    class Electricity
    {
    public static void main(String args[])
    {
    Scanner sc = new Scanner(System.in);
    System.out.print("Name: ");
    String name = sc.nextLine();
    System.out.print("Units: ");
    int u = sc.nextInt();
    double bill;
  2. if (u <= 100)
    bill = u * 2.0;
    else if (u <= 300)
    bill = 100 * 2.0 + (u - 100) * 3.0;
    else
    bill = 100 * 2.0 + 200 * 3.0 + (u - 300) * 5.0;
  3. System.out.println("Name: " + name);
    System.out.println("Bill = " + bill);
    }
    }
  4. Trace 350 units: 200.0 + 600.0 + 50 × 5.0 = 1050.0.
  5. Trace 250 units: 200.0 + 150 × 3.0 = 650.0. Trace 80 units: 160.0.

Answer: Sample run:
Name: R Mehta
Units: 350
Name: R Mehta
Bill = 1050.0

Example 7: Triangle classifier · 15 marks · Long answerHOTS / competency

Write a program to accept three sides of a triangle and print whether it is 'Equilateral', 'Isosceles' or 'Scalene', after first checking that the sides can form a triangle (sum of any two sides greater than the third); otherwise print 'Not a triangle'.

Try it first, then show the solutionSolution
  1. import java.util.Scanner;
    class Triangle
    {
    public static void main(String args[])
    {
    Scanner sc = new Scanner(System.in);
    System.out.print("Three sides: ");
    int a = sc.nextInt(), b = sc.nextInt(), c = sc.nextInt();
  2. if (a + b > c && b + c > a && a + c > b)
    {
    if (a == b && b == c)
    System.out.println("Equilateral");
    else if (a == b || b == c || a == c)
    System.out.println("Isosceles");
    else
    System.out.println("Scalene");
    }
  3. else
    System.out.println("Not a triangle");
    }
    }
  4. Trace 5 5 8: valid (10 > 8, 13 > 5, 13 > 5); not all equal; a == b, so Isosceles.
  5. Trace 1 2 3: 1 + 2 > 3 is false, so Not a triangle.

Answer: Sample runs: 5 5 8 → Isosceles; 6 6 6 → Equilateral; 4 5 6 → Scalene; 1 2 3 → Not a triangle.

Case-study practice (Section B style)

Read the situation, then answer every part. In the board paper this is a 10-mark question split into 2 + 3 + 5 marks.

Courier charges

Imagine a courier company charges ₹800 per kg for the first 5 kg, ₹700 per kg for the next 5 kg and ₹500 per kg above 10 kg; international parcels cost ₹1,500 extra. A student's program uses char type = sc.next().charAt(0); and the condition if (w < 5) for the first slab.

  1. (i) · 2 marks

    What is the charge for a domestic parcel of 8 kg?

    Answer

    Answer: 5 × 800 + 3 × 700 = 4000 + 2100 = ₹6,100.

    Slab split 1 mark; answer 1 mark.

  2. (ii) · 3 marks

    What is wrong with if (w < 5) for the first 5 kg? Correct the slab ladder.

    Answer

    Answer: The first slab includes 5 kg, so it must be w <= 5; with w < 5 a 5 kg parcel is sent to the second branch. Ladder: if (w <= 5) bill = w * 800; else if (w <= 10) bill = 5 * 800 + (w - 5) * 700; else bill = 5 * 800 + 5 * 700 + (w - 10) * 500;

    Error 1 mark; ladder 2 marks.

  3. (iii) · 5 marks

    Add the international charge using the type character and find the bill for a 12 kg international parcel.

    Answer

    Answer: if (type == 'I') bill = bill + 1500; For 12 kg: 4000 + 3500 + 2 × 500 = 8500; + 1500 = ₹10,000.

    Condition 2 marks; calculation 3 marks.

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 without break (fall through). (2 marks) (2 marks)

StepMarks
Correct starting case identified.1
Fall through to the break traced; final output.1

Program: slab-based electricity bill. (15 marks) (15 marks)

StepMarks
Class, main, Scanner; name and units accepted.3
First slab condition and charge.3
Second slab with full first slab added.3
Third slab with both full slabs added.3
Output of name and bill.2
Correct relational operators at boundaries.1

Where students lose marks in Conditional Constructs in Java

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

  • Mistake: Wrong slab calculation or relational operator

    The 2024 examiners reported wrong slab calculations and relational operator syntax in the courier program; in 2025 candidates did not use the slab method for cloud storage.

    Do this: Charge each slab at its own rate and add the full lower slabs; check <= at 'up to' boundaries.

    Usually costs: 3 to 6 marks of 15.

  • Mistake: Answering 'wrong expression' for a condition given in words

    In 2024 candidates treated if (a>b&&b>c) as a Java statement to judge rather than a logical condition.

    Do this: Read what the condition means: a > b > c.

    Usually costs: 1 mark.

  • Mistake: Forgetting break

    Missing break causes fall through and extra output.

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

    Usually costs: 1 to 2 marks.

  • Mistake: Using double in switch

    The 2024 MCQ tested this.

    Do this: switch: int, char, String, byte, short only.

    Usually costs: 1 mark.

Practice questions on Conditional Constructs 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 · MCQBoard level

    Which statement terminates a program?
    (a) break
    (b) continue
    (c) System.exit(0)
    (d) return 0

    Hint

    Whole program.

    Answer

    (c) System.exit(0)

  2. Q2 · 1 mark · MCQBoard level

    In a switch, the block that runs when no case matches is:
    (a) else
    (b) default
    (c) break
    (d) case 0

    Hint

    Fallback.

    Answer

    (b) default

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

    Give the output: char ch = 'b'; switch (ch) { case 'a': System.out.print(1); case 'b': System.out.print(2); case 'c': System.out.print(3); default: System.out.print(4); }

    Hint

    No breaks anywhere.

    Answer

    234

  4. Q4 · 2 marks · Very short answerBoard level

    Rewrite using if-else: res = (n % 3 == 0) ? "Multiple" : "Not multiple";

    Hint

    Ternary to if.

    Answer

    if (n % 3 == 0)
    res = "Multiple";
    else
    res = "Not multiple";

  5. Q5 · 2 marks · Very short answerHarder board level

    Find the error: if (x = 5) System.out.println("Five");

    Hint

    Assignment vs comparison.

    Answer

    x = 5 is an assignment giving an int, but if needs a boolean, so it is a compile-time error. Correct: if (x == 5)

  6. Q6 · 2 marks · Short answerHarder board level

    int a = 10, b = 20; Give the output:
    if (a > b)
    System.out.println("X");
    else
    System.out.println("Y");
    System.out.println("Z");

    Hint

    Only one statement in else.

    Answer

    Y
    Z (Z is outside the if-else and always prints)

  7. Q7 · 15 marks · Long answerBoard level

    Write a program to accept a number and print whether it is positive, negative or zero, and if positive whether it is even or odd.

    Hint

    Nested if inside the positive branch.

    Answer

    import java.util.Scanner;
    class Check
    {
    public static void main(String args[])
    {
    Scanner sc = new Scanner(System.in);
    System.out.print("Number: ");
    int n = sc.nextInt();
    if (n > 0)
    {
    System.out.println("Positive");
    if (n % 2 == 0)
    System.out.println("Even");
    else
    System.out.println("Odd");
    }
    else if (n < 0)
    System.out.println("Negative");
    else
    System.out.println("Zero");
    }
    }
    Sample runs: 7 → Positive, Odd; -4 → Negative; 0 → Zero.

  8. Q8 · 15 marks · Long answerHOTS / competency

    Suppose a shop gives a 5% discount on bills up to ₹2,000, 10% on bills above ₹2,000 up to ₹5,000, and 15% above ₹5,000. Write a program to accept the bill amount and print the discount rate and the net amount. Show the output for bills of ₹5,000 and ₹6,000.

    Hint

    Boundary 5,000 is in the 10% slab.

    Answer

    import java.util.Scanner;
    class Discount
    {
    public static void main(String args[])
    {
    Scanner sc = new Scanner(System.in);
    System.out.print("Bill amount: ");
    double b = sc.nextDouble();
    int d;
    if (b <= 2000)
    d = 5;
    else if (b <= 5000)
    d = 10;
    else
    d = 15;
    double net = b - b * d / 100.0;
    System.out.println("Discount: " + d + "%");
    System.out.println("Net amount = " + net);
    }
    }
    For 5000: Discount: 10% and Net amount = 4500.0 (5000 − 500). For 6000: Discount: 15% and Net amount = 5100.0 (6000 − 900).

  9. Q9 · 2 marks · Short answerHOTS / competency

    Why is switch not suitable for checking marks in ranges such as 60 to 74?

    Hint

    Equality only.

    Answer

    switch compares the value only for equality with constant case labels; it cannot test a range, so you would need a separate case for every mark. An if-else-if ladder with m >= 60 && m < 75 is suitable.

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.Does switch accept String?Show answer

    Yes.

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

    Exits the switch, preventing fall through.

  3. 3.Which if does an else pair with?Show answer

    The nearest unmatched if above it.

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

    Terminates the program normally.

  5. 5.Can switch test a range?Show answer

    No; only equality with constants.

Best order to study it

  1. if and if-else; braces and the stray semicolon.
  2. if-else-if ladders for slabs and grades.
  3. Nested if and dangling else.
  4. switch, break, default, fall through.
  5. Menu-driven programs and System.exit(0).

Quick revision checklist

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

  • if / if-else / if-else-if / nested if.
  • switch: int, char, String, byte, short; constant unique cases.
  • No break → fall through; default → no match.
  • Slabs: if-else-if with <= boundaries.
  • System.exit(0) ends the program.

Conditional Constructs in Java: frequently asked questions

Is default compulsory in switch?

No, but it is good practice for handling invalid input.

Can I use && in a case label?

No. Case labels must be constant values; use if-else-if for compound conditions.

Should I use braces for a single statement?

They are optional, but using them avoids errors when more statements are added.

Based on: CISCE ICSE 2027 Computer Applications syllabus; CISCE Analysis of Pupil Performance ICSE 2025: Computer Applications (with the 2025 board paper)