What are number format exceptions in Java?

Java 8Object Oriented ProgrammingProgramming

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)
raja
Published on 11-Jan-2018 05:09:54
Advertisements