State the type of errors if any in the following statements:
(i) switch ( 2 );
(ii) System.out.println(670/0);
pls answer
Answers
Answered by
1
Answer:
(i)switch(2);
- This is a syntax error, there should be no semicolon after switch statement
The correct Statement is:-
switch(2)
____________
ii)System.out.println(670/0);
- Division by zero is a runtime error.
Answered by
2
I. A switch statement can't be written without a body.
It is termed as a Syntax error.
It can be fixed by adding { } instead of a semicolon.
II. 670 / 0 causes an Arithmetic Exception.
It is termed as a Runtime error.
It can be prevented by using a try-catch block or altogether avoiding division with zero by designing the code in such a way.
Similar questions