当前位置: 首页 > 面试题库 >

线程“ main”中的异常java.lang.NumberFormatException:对于输入字符串:“ S”

佟涵畅
2023-03-14
问题内容

当我尝试将Integer.parseInt()与单个字符一起使用时,出现此错误。

String s = "s";
System.out.println((char) Integer.parseInt(s));

是什么给我的错误是这样的:

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

问题答案:

字母S不是数字。您是要写数字5吗?

String s = "5";
System.out.println((char) Integer.parseInt(s));

还是您要打印字符的ASCII或Unicode值S

char s = 's';
System.out.println((int) s);


 类似资料: