是关于java的一个编程题,希望大家帮帮忙啊,从键盘上输入学生的成绩,然后统计学生成绩的分布情况

设计一个程序,从键盘上输入学生的成绩,然后统计学生成绩的分布情况。要求统计出0~9分,10~19分,20~29分,…,90~99分,100分各区段的成绩个数,用一个“*”... 设计一个程序,从键盘上输入学生的成绩,然后统计学生成绩的分布情况。要求统计出0~9分,10~19分,20~29分,…,90~99分,100分各区段的成绩个数,用一个“*”代表这个分数段有一个学生。 展开
 我来答
雷小音
2012-02-23
知道答主
回答量:29
采纳率:0%
帮助的人:18.3万
展开全部
验证过了,可以一直输入成绩,直到输入任意一个负数退出。
import java.util.Scanner;

public class Statistics {
private static int stuScore = 0;
private static int cntFor0and9 = 0;
private static int cntFor10and19 = 0;
private static int cntFor20and29 = 0;
private static int cntFor30and39 = 0;
private static int cntFor40and49 = 0;
private static int cntFor50and59 = 0;
private static int cntFor60and69 = 0;
private static int cntFor70and79 = 0;
private static int cntFor80and89 = 0;
private static int cntFor90and99 = 0;
private static int cntFor100 = 0;

public static void main(String[] args) {
System.out.println("请输入学生成绩");
Scanner scanner = new Scanner(System.in);
stuScore = scanner.nextInt();
while (stuScore > 0) {
calculater();
stuScore = scanner.nextInt();
}
print();
}

public static void calculater() {

if (stuScore < 10) {
cntFor0and9++;
} else if (stuScore < 20) {
cntFor10and19++;
} else if (stuScore < 30) {
cntFor20and29++;
} else if (stuScore < 40) {
cntFor30and39++;
} else if (stuScore < 50) {
cntFor40and49++;
} else if (stuScore < 60) {
cntFor50and59++;
} else if (stuScore < 70) {
cntFor60and69++;
} else if (stuScore < 80) {
cntFor70and79++;
} else if (stuScore < 90) {
cntFor80and89++;
} else if (stuScore < 100) {
cntFor90and99++;
} else if (stuScore == 100) {
cntFor100++;
}

}

public static void print() {

System.out.print("0 ~ 9分有");
for (int i = 1; i <= cntFor0and9; i++) {
System.out.print("*");
}
System.out.println();

System.out.print("10 ~ 19分有");
for (int i = 1; i <= cntFor10and19; i++) {
System.out.print("*");
}
System.out.println();

System.out.print("20 ~ 29分有");
for (int i = 1; i <= cntFor20and29; i++) {
System.out.print("*");
}
System.out.println();

System.out.print("30 ~ 39分有");
for (int i = 1; i <= cntFor30and39; i++) {
System.out.print("*");
}
System.out.println();

System.out.print("40 ~ 49分有");
for (int i = 1; i <= cntFor40and49; i++) {
System.out.print("*");
}
System.out.println();

System.out.print("50 ~ 59分有");
for (int i = 1; i <= cntFor50and59; i++) {
System.out.print("*");
}
System.out.println();

System.out.print("60 ~ 69分有");
for (int i = 1; i <= cntFor60and69; i++) {
System.out.print("*");
}
System.out.println();

System.out.print("70 ~ 79分有");
for (int i = 1; i <= cntFor70and79; i++) {
System.out.print("*");
}
System.out.println();

System.out.print("80 ~ 89分有");
for (int i = 1; i <= cntFor80and89; i++) {
System.out.print("*");
}
System.out.println();

System.out.print("90 ~ 99分有");
for (int i = 1; i <= cntFor90and99; i++) {
System.out.print("*");
}
System.out.println();

System.out.print("100分有");
for (int i = 1; i <= cntFor100; i++) {
System.out.print("*");
}
System.out.println();

}
}
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
aqbbsxiao
2012-02-23 · TA获得超过105个赞
知道答主
回答量:156
采纳率:0%
帮助的人:98.5万
展开全部
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class test {

public static void main(String[] args) throws IOException {
String score0 = "";
String score1 = "";
String score2 = "";
String score3 = "";
String score4 = "";
String score5 = "";
String score6 = "";
String score7 = "";
String score8 = "";
String score9 = "";
String score10 = "";
BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in));
System.out.println("input score(space character is ','): ");
String str = stdin.readLine();
System.out.println(str);
String arr[] = str.split(",");
for (int i = 0; i < arr.length; i++) {
//我这里没有做数字的有效性验证问题,输入字母什么的就会出异常
if (arr[i] == null || arr[i] == "" || arr[i].length() == 0) continue;
int scoreValue = Integer.valueOf(arr[i]);

// 0 ~ 9
if (scoreValue >= 0 && scoreValue <= 9) score0 += "*";
// 10 ~ 19
else if (scoreValue >= 10 && scoreValue <= 19) score1 += "*";
// 20 ~ 29
else if (scoreValue >= 20 && scoreValue <= 29) score2 += "*";
// 30 ~ 39
else if (scoreValue >= 30 && scoreValue <= 39) score3 += "*";
// 40 ~ 49
else if (scoreValue >= 40 && scoreValue <= 49) score4 += "*";
// 50 ~ 59
else if (scoreValue >= 50 && scoreValue <= 59) score5 += "*";
// 60 ~ 69
else if (scoreValue >= 60 && scoreValue <= 69) score6 += "*";
// 70 ~ 79
else if (scoreValue >= 70 && scoreValue <= 79) score7 += "*";
// 80 ~ 89
else if (scoreValue >= 80 && scoreValue <= 89) score8 += "*";
// 90 ~ 99
else if (scoreValue >= 90 && scoreValue <= 99) score9 += "*";
// 100
else if (scoreValue == 100) score10 += "*";
}
System.out.println("0 ~ 9: " + score0 + " " + score0.trim().length());
System.out.println("10 ~ 19: " + score1 + " " + score1.trim().length());
System.out.println("20 ~ 29: " + score2 + " " + score2.trim().length());
System.out.println("30 ~ 39: " + score3 + " " + score3.trim().length());
System.out.println("40 ~ 49: " + score4 + " " + score4.trim().length());
System.out.println("50 ~ 59: " + score5 + " " + score5.trim().length());
System.out.println("60 ~ 69: " + score6 + " " + score6.trim().length());
System.out.println("70 ~ 79: " + score7 + " " + score7.trim().length());
System.out.println("80 ~ 89: " + score8 + " " + score8.trim().length());
System.out.println("90 ~ 99: " + score9 + " " + score9.trim().length());
System.out.println("100: " + score10 + " " + score10.trim().length());

}

}
本回答被提问者和网友采纳
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式