Chapter 8: Conditional Statements in Java
Answer Key & Exam Preparation
Section 1
A. Multiple Choice Questions
1. Conditional statements in Java are mainly used for → a. Making decisions in a
program
2. Decision-making statements are also known as → d. Selection statements
3. Fall-through in a switch block refers to → b. Execution continuing to the next case
when break is missing
4. The break keyword is used to → c. Immediately exit a loop or switch block
5. The structure in the illustration (Condition 1 → Condition 2 → Statement 1 / Statement
2 → Body of else) is a Nested if-else statement
B. Assertion–Reason Questions
Options: a. Both true, R explains A b. Both true, R does NOT explain A c. A true, R
false d. A false, R true
1. A: Nested if statements allow multiple levels of decision-making. R: An if can appear
inside another if/else block.
→ (a) — both true, R correctly explains A.
2. A: The break statement can also be used inside switch. R: The break statement can only
be used inside loops.
→ (c) — A is true, but R is false (break works in loops and switch, not loops only).
3. A: if-else lets a program choose between two blocks of code. R: if-else executes depending
on whether the condition is true or false.
→ (a) — both true, R explains A.
4. A: Only one block of statements executes in an if-else-if ladder. R: As soon as a condition
evaluates true, that block runs and the rest of the ladder is skipped.
→ (a) — both true, R explains A.
5. A: In [Link](n), 0 indicates normal termination. R: The break statement helps
execute only one case at a time.
→ (b) — both individually true, but R does not explain A.
Note: Because the scan is partly blurred/folded, double-check the option lettering against your
book page — the reasoning above follows the standard concept in each pair.
1
C. Case Study — Food Menu Program
The blank (#statement1) should be filled with the variable being tested:
1 switch ( op )
Since op is a char holding ’H’, ’P’, or ’B’, and the cases are case ’H’:, case ’P’:, case
’B’:, the switch expression must be op.
(The separate “What will be the output” MCQ referencing options 14/12/5/21 is attached to
a code snippet obscured in the scan by a fold — I can’t verify that answer without a clearer
image.)
Section 2 (Unsolved Questions)
A. Very Short Answer
1. Syntax of the if statement:
1 if ( condition )
2 statement ;
2. Use of break in switch-case: The break statement is used inside a switch block
to transfer control out of the switch once a matching case’s statements have executed.
Without it, execution “falls through” into the next case regardless of whether its condition
matches.
3. (Assuming the condition compares x and y, i.e. if(x > y), since x=4 and y=10): the
condition 4 > 10 is false, so the if-block doesn’t execute — x stays 4 and y stays 10.
4.
1 int a = 30 , b = 25;
2 if ( a > 10) { a ++; b ++; }
3 System . out . println ( a + " , " + b ) ;
a > 10 (30>10) is true → a becomes 31, b becomes 26.
Output: 31 , 26
B. Short Answer
1. Difference between if-else and switch-case:
if-else switch-case
Selects between two alternatives Selects among multiple alternatives
Condition can use any relational/logi- Compares one variable/expression
cal expression against fixed values
Works with any data type (int, float, Works only with int or char (String al-
double, char) lowed from JDK7)
Can test a range of values Can only test discrete, single values —
not ranges
2. Statement to find square of the bigger of two numbers:
1 int bigger = ( a > b ) ? a : b ;
2 int square = bigger * bigger ;
2
3. Dangling-else problem: It’s the ambiguity that arises in a nested if structure when
there are more ifs than elses — it becomes unclear which if a given else belongs to.
Java resolves this by always matching an else to the nearest unmatched preceding if.
4. Fall-through in switch-case: When the break statement is omitted after a case’s state-
ments, execution doesn’t stop there — it continues (“falls through”) into the statements
of the next case(s), even if their condition doesn’t match, until a break or the end of the
switch is reached.
5. Significance of default in switch-case: The default case executes when none of the
specified case values match the switch expression. It’s optional, but it’s good practice to
include it to handle invalid/unexpected input.
C. Application-Based Programs
1. Voting eligibility
1 import java . util .*;
2 class VoteCheck {
3 public static void main ( String args []) {
4 Scanner sc = new Scanner ( System . in ) ;
5 System . out . print ( " Enter age : " ) ;
6 int age = sc . nextInt () ;
7 if ( age >= 18)
8 System . out . println ( " Eligible to vote " ) ;
9 else
10 System . out . println ( " Not eligible to vote " ) ;
11 }
12 }
2. Cube of the bigger of two numbers
1 import java . util .*;
2 class CubeBigger {
3 public static void main ( String args []) {
4 Scanner sc = new Scanner ( System . in ) ;
5 System . out . print ( " Enter two numbers : " ) ;
6 int a = sc . nextInt () , b = sc . nextInt () ;
7 int big = ( a > b ) ? a : b ;
8 System . out . println ( " Cube of bigger number = " + ( big * big * big ) ) ;
9 }
10 }
3. Leap year check
1 import java . util .*;
2 class LeapYear {
3 public static void main ( String args []) {
4 Scanner sc = new Scanner ( System . in ) ;
5 System . out . print ( " Enter year ( yyyy ) : " ) ;
6 int y = sc . nextInt () ;
7 if (( y % 4 == 0 && y % 100 != 0) || y % 400 == 0)
8 System . out . println ( y + " is a leap year " ) ;
9 else
10 System . out . println ( y + " is not a leap year " ) ;
11 }
12 }
4 & 5. Discount based on purchase amount (Goods worth ≤5000 → 10% discount, >5000
→ 15% discount)
3
1 import java . util .*;
2 class Discount {
3 public static void main ( String args []) {
4 Scanner sc = new Scanner ( System . in ) ;
5 System . out . print ( " Enter purchase amount : " ) ;
6 double p = sc . nextDouble () ;
7 double discount , net ;
8 if ( p <= 5000)
9 discount = p * 0.10;
10 else
11 discount = p * 0.15;
12 net = p - discount ;
13 System . out . println ( " Discount = " + discount ) ;
14 System . out . println ( " Net payment = " + net ) ;
15 }
16 }
6. Menu-based calculator (sum, difference, product, division)
1 import java . util .*;
2 class Calculator {
3 public static void main ( String args []) {
4 Scanner sc = new Scanner ( System . in ) ;
5 System . out . print ( " Enter two numbers : " ) ;
6 int a = sc . nextInt () , b = sc . nextInt () ;
7 System . out . println ( " 1: Sum \ n2 : Difference \ n3 : Product \ n4 : Division " ) ;
8 System . out . print ( " Enter choice : " ) ;
9 int ch = sc . nextInt () ;
10 switch ( ch ) {
11 case 1: System . out . println ( " Sum = " + ( a + b ) ) ; break ;
12 case 2: System . out . println ( " Difference = " + (a - b ) ) ; break ;
13 case 3: System . out . println ( " Product = " + ( a * b ) ) ; break ;
14 case 4:
15 System . out . println ( " Quotient = " + ( a / b ) ) ;
16 System . out . println ( " Remainder = " + ( a % b ) ) ;
17 break ;
18 default : System . out . println ( " Invalid choice " ) ;
19 }
20 }
21 }
7. Buzz number check (ends in 7 OR divisible by 7)
1 import java . util .*;
2 class BuzzNumber {
3 public static void main ( String args []) {
4 Scanner sc = new Scanner ( System . in ) ;
5 System . out . print ( " Enter a number : " ) ;
6 int n = sc . nextInt () ;
7 if ( n % 10 == 7 || n % 7 == 0)
8 System . out . println ( n + " is a Buzz number " ) ;
9 else
10 System . out . println ( n + " is not a Buzz number " ) ;
11 }
12 }
Age category (child/teenager/adult/old)
1 import java . util .*;
2 class AgeGroup {
3 public static void main ( String args []) {
4 Scanner sc = new Scanner ( System . in ) ;
4
5 System . out . print ( " Enter age : " ) ;
6 int age = sc . nextInt () ;
7 if ( age <= 12)
8 System . out . println ( " Child " ) ;
9 else if ( age >= 13 && age <= 19)
10 System . out . println ( " Teenager " ) ;
11 else if ( age >= 20 && age <= 50)
12 System . out . println ( " Adult " ) ;
13 else
14 System . out . println ( " Old " ) ;
15 }
16 }
8. Menu for rectangle: area, perimeter, diagonal
1 import java . util .*;
2 class RectangleMenu {
3 public static void main ( String args []) {
4 Scanner sc = new Scanner ( System . in ) ;
5 System . out . print ( " Enter length and breadth : " ) ;
6 double l = sc . nextDouble () , b = sc . nextDouble () ;
7 System . out . println ( " 1: Area \ n2 : Perimeter \ n3 : Diagonal " ) ;
8 System . out . print ( " Enter choice : " ) ;
9 int ch = sc . nextInt () ;
10 switch ( ch ) {
11 case 1: System . out . println ( " Area = " + ( l * b ) ) ; break ;
12 case 2: System . out . println ( " Perimeter = " + (2*( l + b ) ) ) ; break ;
13 case 3: System . out . println ( " Diagonal = " + Math . sqrt ( l * l + b * b ) ) ;
break ;
14 default : System . out . println ( " Invalid choice " ) ;
15 }
16 }
17 }
9. Time unit converter (menu-driven, switch)
1 import java . util .*;
2 class TimeConverter {
3 public static void main ( String args []) {
4 Scanner sc = new Scanner ( System . in ) ;
5 System . out . println ( " 1: Days to weeks \ n2 : Months to years \ n3 : Days to
years " ) ;
6 System . out . print ( " Enter choice : " ) ;
7 int ch = sc . nextInt () ;
8 System . out . print ( " Enter value : " ) ;
9 double val = sc . nextDouble () ;
10 switch ( ch ) {
11 case 1: System . out . println ( " Weeks = " + ( val /7) ) ; break ;
12 case 2: System . out . println ( " Years = " + ( val /12) ) ; break ;
13 case 3: System . out . println ( " Years = " + ( val /365) ) ; break ;
14 default : System . out . println ( " Invalid choice " ) ;
15 }
16 }
17 }
10. Menu-driven square/cube
1 import java . util .*;
2 class SquareCube {
3 public static void main ( String args []) {
4 Scanner sc = new Scanner ( System . in ) ;
5 System . out . print ( " Enter a number : " ) ;
6 double n = sc . nextDouble () ;
5
7 System . out . println ( " 1: Square \ n2 : Cube " ) ;
8 System . out . print ( " Enter choice : " ) ;
9 int ch = sc . nextInt () ;
10 switch ( ch ) {
11 case 1: System . out . println ( " Square = " + ( n * n ) ) ; break ;
12 case 2: System . out . println ( " Cube = " + ( n * n * n ) ) ; break ;
13 default : System . out . println ( " Invalid choice " ) ;
14 }
15 }
16 }
Likely ICSE Class 9 Theory-Exam Questions From This Chapter
Based on how this topic is typically tested in ICSE Computer Applications theory papers:
Definition/concept questions (2 marks each)
Define decision-making (selection) statements. Name the types available in Java.
What is the difference between if-else and if-else-if?
What is the dangling-else problem? Give an example.
What is meant by “fall-through” in a switch statement? How can it be avoided?
Why is break important in a switch-case block?
What data types can be used in switch expressions?
What is the purpose of the default case in switch?
Differentiate between if-else and switch-case (table format — very commonly asked).
What does [Link](0) do, and how is it different from a normal program end?
Code output / trace questions (2–3 marks)
Given a code snippet with nested if / if-else / if-else-if or switch (with or without break),
predict the output.
Identify errors in a given switch-case or if-else code snippet.
Convert a given if-else-if ladder into an equivalent switch-case statement, or vice versa.
Programming questions (4–6 marks) — the most heavily weighted
Menu-driven programs (calculator, geometry area finder, unit converter, bill/fare calcula-
tor with slab rates) — these are a favorite exam pattern.
Grade/category assignment based on marks, age, or amount (if-else-if ladder).
Number properties: Buzz number, Armstrong-style checks, vowel/consonant/character
classification using switch.
Real-life slab-based billing (electricity, fare, tax, discount) — appears almost every year
in some form.
Triangle formation/type check using nested if with logical operators.
6
Assertion-Reason and case-study style
A newer ICSE pattern, as seen in your book — expect 1–2 of these based on core concepts:
nested if, break behavior, switch restrictions, dangling-else.