Bird
0
0

What exception is thrown when Integer.parseInt attempts to parse the string "12a3" in Java?

easy📝 Conceptual Q2 of 15
Java - Command Line Arguments

What exception is thrown when Integer.parseInt attempts to parse the string "12a3" in Java?

ANumberFormatException
BNullPointerException
CIllegalArgumentException
DClassCastException
Step-by-Step Solution
Solution:
  1. Step 1: Understand the input string

    The string "12a3" contains a non-numeric character 'a', which is invalid for integer parsing.
  2. Step 2: Identify the exception thrown

    Integer.parseInt throws NumberFormatException when the string cannot be parsed as a valid integer.
  3. Final Answer:

    NumberFormatException -> Option A
  4. Quick Check:

    Invalid numeric format triggers NumberFormatException [OK]
Quick Trick: Invalid numeric strings cause NumberFormatException [OK]
Common Mistakes:
  • Assuming NullPointerException without null input
  • Confusing with IllegalArgumentException
  • Expecting ClassCastException for parsing errors

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Java Quizzes