我调用过其他两个Integer方法但是都是同一个Exception:NumberFormatException,所以搞不懂了。
public class Test{
String s = "a";
int i;
public int result(){
return i = (new Integer(s).intValue());
}
public static void main(String[] args){
Test myTest = new Test();
int a = myTest.result();
System.out.println(a);
}
}
public class Test{
String s = "a";
int i;
public int result(){
return i = (new Integer(s).intValue());
}
public static void main(String[] args){
Test myTest = new Test();
int a = myTest.result();
System.out.println(a);
}
}
就是,s="a";
a是数字吗???只有是数字的字符串才可以转;
public class Test{
String s = "a";
int i;
public int result(){
return i = (new Integer(s.hashCode()).intValue());
}
public static void main(String[] args){
Test myTest = new Test();
int a = myTest.result();
System.out.println(a);
}
}
单纯强制转换a为数字估计不行吧
char s = 'a';
int i = s;
System.out.println(i);
}
char a='A';
System.out.println(new Integer(a));