numberformatexception in java code example
Example 1: numberformatexception
package com.devdaily.javasamples;
public class ConvertStringToNumber {
public static void main(String[] args) {
try {
String s = "FOOBAR";
int i = Integer.parseInt(s);
System.out.println("int value = " + i);
}
catch (NumberFormatException nfe) {
nfe.printStackTrace();
}
}
}
Example 2: NumberFormatException
Thrown to indicate that the application has attempted to convert a string to one of the numeric types, but that the string does not have the appropriate format.