JAVA問題總結16-一維數組案例

來源:互聯網
上載者:User

標籤: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-一維數組案例

聯繫我們

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