java 從鍵盤輸入學產生績,找出最高分,並輸出學產生績等級。

來源:互聯網
上載者:User

標籤:學生   ati   char   scan   class   string   port   import   evel   

/*從鍵盤輸入學產生績,找出最高分,並輸出學產生績等級;
成績 >=最高分-10 等級為A
成績 >=最高分-20 等級為B
成績 >=最高分-30 等級為C
其餘為 等級為D

提示:先輸入學生人數,根據人數建立int數組,存放學產生績;
*/


package study01;import java.util.Scanner;public class Score { public static void main(String[] args) { Scanner sc = new Scanner(System.in); System.out.print("請輸入學生人數:"); int length = sc.nextInt(); int[] scores = new int[length]; int maxScore = 0; for (int i = 0; i < scores.length; i++) { scores[i] = sc.nextInt(); if (scores[i] > maxScore) { maxScore = scores[i]; } } System.out.println("最高分" + maxScore); System.out.println("輸入的成績為:"); for (int i = 0; i < scores.length; i++) { char level; if (scores[i] > maxScore - 10) { level = ‘A‘; } else if (scores[i] > maxScore - 20) { level = ‘B‘; } else if (scores[i] > maxScore - 30) { level = ‘C‘; } else { level = ‘D‘; } System.out.println("student["+i+"] score is "+scores[i]+" grade is "+level); } }}

輸出結果如下:

請輸入學生人數:6
90
70
80
50
60
40
最高分90
輸入的成績為:
student[0] score is 90 grade is A
student[1] score is 70 grade is C
student[2] score is 80 grade is B
student[3] score is 50 grade is D
student[4] score is 60 grade is D
student[5] score is 40 grade is D

 

 

java 從鍵盤輸入學產生績,找出最高分,並輸出學產生績等級。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.