當前位置:編程學習大全網 - 編程語言 - 是關於java的壹個編程題,希望大家幫幫忙啊,從鍵盤上輸入學生的成績,然後統計學生成績的分布情況

是關於java的壹個編程題,希望大家幫幫忙啊,從鍵盤上輸入學生的成績,然後統計學生成績的分布情況

驗證過了,可以壹直輸入成績,直到輸入任意壹個負數退出。

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();

}

}

  • 上一篇:安慶藝術中專學校師資怎麽樣公辦還是民辦地址
  • 下一篇:昆明高級技工學校的學校專業課程與學生就業方向
  • copyright 2024編程學習大全網