是关于java的一个编程题,希望大家帮帮忙啊,从键盘上输入学生的成绩,然后统计学生成绩的分布情况
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了是关于java的一个编程题,希望大家帮帮忙啊,从键盘上输入学生的成绩,然后统计学生成绩的分布情况相关的知识,希望对你有一定的参考价值。
设计一个程序,从键盘上输入学生的成绩,然后统计学生成绩的分布情况。要求统计出0~9分,10~19分,20~29分,…,90~99分,100分各区段的成绩个数,用一个“*”代表这个分数段有一个学生。
参考技术A 验证过了,可以一直输入成绩,直到输入任意一个负数退出。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();
参考技术B 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());
本回答被提问者和网友采纳
以上是关于是关于java的一个编程题,希望大家帮帮忙啊,从键盘上输入学生的成绩,然后统计学生成绩的分布情况的主要内容,如果未能解决你的问题,请参考以下文章