Search code examples
javaparseintnumberformatexception

Number format exception in parse int


public static void main(String[] args)throws IOException {
  String s ="12312a";
  int x = Integer.parseInt(s);
  System.out.println (x+2);
}

and all what I've got is :

Exception in thread "main" java.lang.NumberFormatException: For input string: "12312a"

any hints ?


Solution

  • Perhaps you meant

    int x = Integer.parseInt("12312a", 16);