求大神帮忙编个JAVA,用来统计成绩的程序
下面是做成之后输出的,红色的字是用户输入的,再下面是个统计柱状图,统计每个分数段的数量。
N是新的分数列,A是在N里面增加一些数,分数小于0,大于10的不算,后面输出平均值,最大,最小数,Q是退出程序
数组如果可以的话也行 展开
可怜的小娃娃啊。哥帮你写了。先看效果图(绿色为输入):
代码如下:
package zhidao;
import java.util.Scanner;
public class TestCount {
public static void main(String[] args) {
double total = 0;
int count = 0;
int max = -1;
int min = 11;
int countOthers = 0;
int count6 = 0;
int count7 = 0;
int count8 = 0;
int count9 = 0;
int count10 = 0;
Scanner scanner = new Scanner(System.in);
String line = null;
while(true){
System.out.println("Choose (A: add scores), (N: new scores), or (Q: quit)");
line = scanner.nextLine();
if(line.equalsIgnoreCase("Q")){
break;
}else if(line.equalsIgnoreCase("N")){
total = 0;
count = 0;
max = -1;
min = 11;
countOthers = 0;
count6 = 0;
count7 = 0;
count8 = 0;
count9 = 0;
count10 = 0;
System.out.println("Type the additional scores in single line");
line = scanner.nextLine();
}else if(line.equalsIgnoreCase("A")){
System.out.println("Type a new list of scores in single line");
line = scanner.nextLine();
}
String[] datas = line.split(" ");
for (String data : datas) {
if(!data.matches("^\\d+$")){
continue;
}
int d = Integer.parseInt(data);
if(d < 0 || d > 10){
continue;
}
total += d;
count++;
if(max < d){
max = d;
}
if(min > d){
min = d;
}
switch (d) {
case 10:
count10++;
break;
case 9:
count9++;
break;
case 8:
count8++;
break;
case 7:
count7++;
break;
case 6:
count6++;
break;
default:
countOthers++;
break;
}
}
System.out.println("\n------------------------");
System.out.println(" <6|" + nStart(countOthers));
System.out.println(" 6|" + nStart(count6));
System.out.println(" 7|" + nStart(count7));
System.out.println(" 8|" + nStart(count8));
System.out.println(" 9|" + nStart(count9));
System.out.println(" 10|" + nStart(count10));
System.out.printf("Average = %5.2f\n",total/count);
System.out.printf("Maximum = %5d\n",max);
System.out.printf("Minimum = %5d\n",min);
System.out.println("------------------------\n");
}
System.out.println("*** End of program ***");
}
private static String nStart(int count) {
String s = "";
for (int i = 0; i < count; i++) {
s += "*";
}
return s;
}
}
有疑问请追问或私信我,没有用list和数组,望采纳。