线程“main”中的异常java.lang.NumberFormatException:对于输入字符串:" S" [英] Exception in thread "main" java.lang.NumberFormatException: For input string: "S"

查看:98
本文介绍了线程“main”中的异常java.lang.NumberFormatException:对于输入字符串:" S"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我尝试将Integer.parseInt()与一个char一起使用时,我收到此错误。

I get this error when I try to use Integer.parseInt() with a single char.

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

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

Is what gives me the error is this:

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


推荐答案

字母 S 不是数字。你的意思是写5号吗?

The letter S is not a number. Did you mean to write the number 5?

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

或者你的意思是打印字符的ASCII或Unicode值 S

Or did you mean to print the ASCII or Unicode value of the character S?

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

这篇关于线程“main”中的异常java.lang.NumberFormatException:对于输入字符串:" S"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆