期末考試之分等級(JAVA)__JAVA

來源:互聯網
上載者:User

Problem Description

期末考試結束了,老師想要根據學生們的成績劃分出等級。共有5個等級A,B,C,D和E。
劃分方法如下,90分(含90)以上的為A,80~90(含80)間的為B,70~80(含70)間的為C,
60~70(含60)的為D,不及格的為E。
根據輸入的成績,編程輸出各個層級段人數。

Input

輸入第一行包含一個正整數N(N<= 100)代表學生的數目,接下來有N行資料每行一個整數(0~100)代表
一個學生的成績。
Output

輸出有五行格式如下:
A nA
B nB
C nC
D nD
E nE
其中A,B,C,D,E代表等級,nA,nB等代表個等級的人數,等級和人數之間有一個空格。
Sample Input

6
66
73
85
99
100
59
Sample Output

A 2
B 1
C 1
D 1
E 1

import java.util.Scanner;public class Main{    public static void main(String[] args)    {        Scanner cin = new Scanner(System.in);        int T;        int i;        T = cin.nextInt();        int a, b ,c, d, e;        a = b = c = d = e = 0;        int n;        for(i = 1;i <= T;i ++)        {            n = cin.nextInt();            if(n >= 90) a ++;            if(n < 90 && n >= 80) b ++;            if(n < 80 && n >= 70) c ++;            if(n < 70 && n >= 60) d ++;            if(n < 60) e ++;        }        System.out.println("A" + " " + a);        System.out.println("B" + " " + b);        System.out.println("C" + " " + c);        System.out.println("D" + " " + d);        System.out.println("E" + " " + e);        cin.close();    }}

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.