Java开发网 Java开发网
注册 | 登录 | 帮助 | 搜索 | 排行榜 | 发帖统计  

您没有登录

» Java开发网 » Java SE 综合讨论区  

按打印兼容模式打印这个话题 打印话题    把这个话题寄给朋友 寄给朋友    该主题的所有更新都将Email到你的邮箱 订阅主题
flat modethreaded modego to previous topicgo to next topicgo to back
作者 Re:jdk求救Exception in thread "main" java.io.IOExection:句柄无效。 [Re:zengxiaorong]
archonLing





发贴: 57
积分: 10
于 2003-09-23 09:53 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
I just want to make several points regarding your program:

1. there is a typo in the program, use "toal+=4;" instead "total=+4;".
2. java is very strong in string process. It would easier to use BufferedReder's readLine() function instead of trying manipulate the byte[] inputs when you are dealing with pure String inputs.
3. average calcuation is usually done in float or double in stead of int.

Have fun...
-----------------------------------------------------------------------------------------------

import java.io.*;

public class Average
{
public static void main ( String args[] ) throws IOException
{
int counter,total,average;
String grade;

//counter为计数器,grade储存输入的字符,total,average表示总数和平均数

BufferedReader stdin
= new BufferedReader(new InputStreamReader(System.in));

total=0;
counter=1;

while(counter<=10)
{
System.out.print("输入成绩级别(A,B,C,D,E):");
System.out.flush();
grade= stdin.readLine().trim();

if("A".equals(grade)) total+=4;
else if("B".equals(grade)) total+=3;
else if("C".equals(grade)) total+=2;
else if("D".equals(grade)) total+=1;
else if("E".equals(grade)) total+=0;

//System.in.skip(1);
counter+=1;
}

average=total/10;
System.out.println("平均积分为"+average);
}
}




话题树型展开
人气 标题 作者 字数 发贴时间
5477 jdk求救Exception in thread "main" java.io.IOExection:句柄无效。 zengxiaorong 1161 2003-09-22 10:14
4621 Re:jdk求救Exception in thread "main" java.io.IOExection:句柄无效。 archonLing 604 2003-09-24 17:22
4447 Re:jdk求救Exception in thread "main" java.io.IOExection:句柄无效。 helloworld 128 2003-09-24 17:27
4666 Re:jdk求救Exception in thread "main" java.io.IOExection:句柄无效。 mochow 94 2003-09-22 22:04
4944 Re:jdk求救Exception in thread "main" java.io.IOExection:句柄无效。 archonLing 1356 2003-09-23 09:53
4488 Re:jdk求救Exception in thread "main" java.io.IOExection:句柄无效。 zengxiaorong 116 2003-09-24 08:10
4609 Re:jdk求救Exception in thread "main" java.io.IOExection:句柄无效。 mochow 12 2003-09-24 22:34
4489 Re:jdk求救Exception in thread "main" java.io.IOExection:句柄无效。 llcan 15 2003-10-08 22:01

flat modethreaded modego to previous topicgo to next topicgo to back
  已读帖子
  新的帖子
  被删除的帖子
Jump to the top of page

   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