Computer Applications
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);
Input in Java
7 Likes
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.
Answered By
2 Likes
Related Questions
Write the Java statement for the following mathematical expression :
x =
Find the value of
++a * (a++ + 5) + 3 * --a
, if a = 12.What will be the output of the following code?
int num = 10; if (num < 20) System.out.print(num++); else System.out.print(--num);
Find the output of the given code.
int a, b = 100; for (a = 10; a <= 12; a++) { b += a; } System.out.print("a:" + a + " " + "b:" + b);