java编写成绩统计程序

发布网友 发布时间:2022-04-26 01:21

我来回答

1个回答

热心网友 时间:2022-06-19 09:54

package test;

import java.util.Scanner;

public class Homework {
private static int yx,lh,zd,jg,bjg;
public static void main(String[] args) {
String ff = "";
Scanner s = new Scanner(System.in);
int num = 0;
String flag ;
while(num < 20){
flag = s.nextLine();
if(flag.equals("")){
break;
}
ff = ff + flag + "-";
num ++;
}
int count = ff.split("-").length;
double sum = 0;
int avg = 0;
for(int i=0;i<count;i++){
sum = sum + Double.valueOf((ff.split("-")[i]) );
level(Double.valueOf((ff.split("-")[i])));
}
avg = (int) sum / count;

System.out.println("总人数:"+count+"\n总分:"+sum+"\n平均分值:"+avg);
System.out.println("优秀:"+yx+"\n良好:"+lh+"\n中等:"+zd+"\n及格:"+jg+"\n不及格:"+bjg);

}

private static void level(double d){
if(d>=90){
yx ++;
}else if(d >=80){
lh ++;
}else if(d >=70){
zd ++;
}else if(d>=60){
jg ++;
}else {
bjg ++;
}

}
}

声明声明:本网页内容为用户发布,旨在传播知识,不代表本网认同其观点,若有侵权等问题请及时与本网联系,我们将在第一时间删除处理。E-MAIL:11247931@qq.com