当前位置: 技术问答>java相关
Integer.parseInt出錯,爲什麽?
来源: 互联网 发布时间:2015-08-02
本文导语: class TestInteger { public static void main(String[] args) throws java.io.IOException { System.out.println("Please enter a integer"); String name=""; int c; while((c=System.in.read())!='n') { name+=(char)c; } System.out.println("name="+Integer.parseI...
class TestInteger
{
public static void main(String[] args) throws java.io.IOException
{
System.out.println("Please enter a integer");
String name="";
int c;
while((c=System.in.read())!='n')
{
name+=(char)c;
}
System.out.println("name="+Integer.parseInt(name1));
}
}
//error!
//Exception in thread "main" java.lang.NumberFormatException q00
at java.lang.Integer.parseInt(Integer.java:426)
at ...
{
public static void main(String[] args) throws java.io.IOException
{
System.out.println("Please enter a integer");
String name="";
int c;
while((c=System.in.read())!='n')
{
name+=(char)c;
}
System.out.println("name="+Integer.parseInt(name1));
}
}
//error!
//Exception in thread "main" java.lang.NumberFormatException q00
at java.lang.Integer.parseInt(Integer.java:426)
at ...
|
System.out.println("name="+Integer.parseInt(name.trim()));