Converting aplhanumeric string to numbers - NumberFormatException
I need to get the number 23 from the string "a23". When running the program below, the following error appears.
public class GetIntFromString {
public static void main(String[] args) {
String str = "a23";
int i = Integer.parseInt(str);
System.out.println("Integer value= "+i);
System.out.println("value= "+str);
}
}
Here is the stack trace
Exception in thread "main" java.lang.NumberFormatException: For Input String: "a23"
at java.lang.NumberFormatException.forInputString<NumberFormatException.java.48>
at java.lang.Integer.ParseInt<Integer.java.449>
at java.lang.Integer.ParseInt<Integer.java.499>
at GetIntFromString.main<GetIntFromString.java.9>
+3
source to share
5 answers