ICSE Class 10 Computer Applications Question 25 of 30

Solved Sample Paper 4 — Question 25

Back to all questions
25
Question

Question 2(v)

State the type of errors, if any in the following statements.

(a)

switch (x < 2)

(b)

int a = 100, b = 0;    
System.out.println (a / b);
Answer

(a) There is a syntax error in the switch statement. In a switch statement, the expression inside the parentheses should evaluate to an integer, a character, or an enumerated type. However, x < 2 is a boolean expression, and it cannot be used directly as the expression in a switch statement.

(b) The statement System.out.println (a / b); will result in a runtime error as the user is trying to divide a number by 0 which is not possible.