我得到以下错误
Driver.java:237: cannot find symbol
symbol : method parseInt(char)
location: class java.lang.Integer
int bp = Integer.parseInt(b);使用此代码时
char p = switchchar.charAt(6);
char b = switchchar.charAt(7);
int pp = Integer.parseInt(p);
int bp = Integer.parseInt(b);在文档中,它说方法应该在那里?
发布于 2013-11-25 04:50:03
这是因为Integer#parseInt(String)方法接收的是String而不是char。若要从char获取数值,请使用Character#getNumericValue(char)。
int pp = Character.getNumericValue(p);
int bp = Character.getNumericValue(b);发布于 2013-11-25 04:49:56
在parseInt接受之前,您必须将char转换为字符串。
发布于 2013-11-25 04:52:26
parseInt方法接收字符串作为其参数,而不是char,因此您必须执行如下操作:
String p = "" + switchchar.charAt(6);
String b = "" + switchchar.charAt(7);
int pp = Integer.parseInt(p);
int bp = Integer.parseInt(b);https://stackoverflow.com/questions/20184944
复制相似问题