標籤:java
JAVA問題總結16-一維數組案例
從鍵盤讀入學產生績,找出最高分,並輸出學產生績等級。
成績>=最高分-10 等級為’A’
成績>=最高分-20 等級為’B’
成績>=最高分-30 等級為’C’
其餘 等級為’D’
提示:先讀入學生人數,根據人數建立int數組,存放學產生績
代碼:
package java3;import java.util.Scanner;public class scores {public static void main(String[] args){ Scanner s = new Scanner(System.in); System.out.println("請輸入學生個數"); int all=s.nextInt(); System.out.println("請輸入"+all+"個學生的成績"); int[] ss=new int[all]; int max=0; for (int i=0;i<all;i++){ ss[i]=s.nextInt(); if(ss[i]>max){ max=ss[i]; } } System.out.println("最高成績為:"+max); for (int i=0;i<all;i++){ int j=i+1; if(ss[i]>=max-10){ System.out.println("第"+j+"個同學的成績為"+ss[i]+"等級為:A"); } else if(ss[i]>=max-20){ System.out.println("第"+j+"個同學的成績為"+ss[i]+"等級為:B"); } else if(ss[i]>=max-30){ System.out.println("第"+j+"個同學的成績為"+ss[i]+"等級為:C"); }else{ System.out.println("第"+j+"個同學的成績為"+ss[i]+"等級為:D"); } } }}
結果:
請輸入學生個數5請輸入5個學生的成績5674894189最高成績為:89第1個同學的成績為56等級為:D第2個同學的成績為74等級為:B第3個同學的成績為89等級為:A第4個同學的成績為41等級為:D第5個同學的成績為89等級為:A
著作權聲明:本文為博主原創文章,未經博主允許不得轉載。
JAVA問題總結16-一維數組案例