Topic: 帮忙解决一下问题,看代码错在那里!(NumberFormatException) |
Print this page |
1.帮忙解决一下问题,看代码错在那里!(NumberFormatException) | Copy to clipboard |
Posted by: 海之南山之最 Posted on: 2005-10-22 14:19 请尽量使用准确的文字描述作为标题 It's more desirable to cut-n-paste from the Command Prompt window than to use a Printscreen image. Original subject : 帮忙解决一下问题,看代码错在那里!! 代码!! import java.io.*; public class Zongfen { public static void main(String args[]) { String s=""; int i,j,data,sum; System.out.println("pelase in put number:"); for(i=1;i<=10;i++) {sum=0; for(j=1;j<=5;j++){ try {sum=0; BufferedReader in=new BufferedReader(new InputStreamReader(System.in)); s=in.readLine(); } catch (IOException e){} data=Integer.parseInt(s); sum=sum+data; } System.out.println("zongfen is :" + sum); } } } |
2.Re:帮忙解决一下问题,看代码错在那里!! [Re: 海之南山之最] | Copy to clipboard |
Posted by: ranchgirl Posted on: 2005-10-22 14:48 For input string "80 89 80 84 87"????????? Of couse, "80 89 80 84 87" is not parsable as a number!!!!! You can either enter one number at a time, or use StringTokenizer in your code. |
3.Re:帮忙解决一下问题,看代码错在那里!! [Re: 海之南山之最] | Copy to clipboard |
Posted by: q_yuan Posted on: 2005-10-22 15:46 Is this method of inputing number right? It is right in passcal,but not in JAVA! So you should change your method! |
4.Re:帮忙解决一下问题,看代码错在那里!! [Re: 海之南山之最] | Copy to clipboard |
Posted by: hust313 Posted on: 2005-10-22 19:00 import java.io.*; public class ZongFen{ public static void main(String args[]){ int i,j,data=0,sum=0; System.out.println("pelase in put number:"); for(i=1;i<=10;i++){ for(j=1;j<=5;j++){ try{ BufferedReader in=new BufferedReader(new InputStreamReader(System.in)); data=in.read()-48; } catch (IOException e){ } sum+=data; } System.out.println("zongfen is :" + sum); } } } |
5.Re:帮忙解决一下问题,看代码错在那里!! [Re: 海之南山之最] | Copy to clipboard |
Posted by: 海之南山之最 Posted on: 2005-10-22 22:21 上面的师兄好象不能运行哦?? 看运行后的反应!!错误啊 Please don't use BMP image -- the 680kB image has been removed. In fact, you should just cut-n-paste the content from the Command Prompt window: c:\myjava> java ZongFen Be careful with the name of the class and the java file: ZongFen vs Zongfen |
6.Re:帮忙解决一下问题,看代码错在那里!! [Re: 海之南山之最] | Copy to clipboard |
Posted by: leiqlion Posted on: 2005-10-30 18:48 至少要加一个(int) |
7.Re:帮忙解决一下问题,看代码错在那里!(NumberFormatException) [Re: 海之南山之最] | Copy to clipboard |
Posted by: xfhu Posted on: 2005-11-02 11:58 应该每输入一个整数之后要敲一个回车的. pelase in put number: 1 2 3 4 5 zongfen is :15 还有我去掉了:sum=0; |
Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1 客服电话 18559299278 客服信箱 714923@qq.com 客服QQ 714923 |