What are number format exceptions in Java?


This Exception happens once you associated convert a string variable in an incorrect format to a whole number (numeric format) that's not compatible with one another.

Example

public class Test {
   public static void main(String[] args) {
      int data = Integer.parseInt("hello");
   }
}

Output

Exception in thread "main" java.lang.NumberFormatException: For input
string: "hello"
   at java.lang.NumberFormatException.forInputString(Unknown Source)
   at java.lang.Integer.parseInt(Unknown Source)
   at java.lang.Integer.parseInt(Unknown Source)
   at a6.dateAndTime.Test.main(Test.java:5)

Sai Subramanyam
Sai Subramanyam

Passionate, Curious and Enthusiastic.

Updated on: 30-Jul-2019

129 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements