JAVA Programming :: Basic Concepts - Discussion
Home > JAVA Programming > Basic Concepts > MCQs Questions Discussion
19 / 64
Which Exception Will occur
class Test {
public static void main(String[ ] args) {
try {
String s = "5.6";
Integer.parseInt(s); // Cause a NumberFormatException
int i = 0;
int y = 2 / i;
System.out.println("Welcome to Java");
} catch (Exception ex) {
System.out.println(ex);
}
}
}
class Test {
public static void main(String[ ] args) {
try {
String s = "5.6";
Integer.parseInt(s); // Cause a NumberFormatException
int i = 0;
int y = 2 / i;
System.out.println("Welcome to Java");
} catch (Exception ex) {
System.out.println(ex);
}
}
}
ANumberFormatException
BWelcome to Java
CCompiler Error
DNone
Answer: Option (Login/Signup)
Show Explanation
Asked In ::
STEP-BY-STEP
Here, at line 5, we will get a RuntimeException, saying java.lang.NumberFormatException: For input string: "5.6".
NumberFormatException occurs when we are trying to convert String to number, and the number is not properly formatted.
Here 5.6 is of string type, and the parseInt() method does convert string to int, but 5.6 can only be converted to double or float type from string, and not to int type.
Read Full Answer
Report Error
Please Login First Click Here