java程式碼範例(5)

來源:互聯網
上載者:User

標籤:int   二維數組   for   print   程式碼範例   ring   數組   scanner   next   

 1 /** 2  * 需求分析:從鍵盤輸入5名學員某門課程的筆試成績,並求出五門成績的總成績和平均成績 3  * @author chenyanlong 4  * 日期:2017/10/14 5  */ 6 package com.hp.test05; 7  8 import java.util.Scanner; 9 10 public class HS_Array1 {11 12     public static void main(String[] args) {13         // TODO Auto-generated method stub14         System.out.println("請輸入5個學生的筆試成績:");15         16         double sum=0;17         double avg;18         int[] scores = new int[6];19         Scanner input=new Scanner(System.in);20         //輸入5個成績21         for(int i=0;i<5;i++){22             23             scores[i]=input.nextInt();24         }25         //求和26         for(int j=0;j<5;j++){27             sum=sum+scores[j];28         }29         System.out.println("總成績:"+sum);30         //平均分31         avg=sum/5;32         System.out.println("平均分:"+avg);           33     }34 }
 1 /** 2  * 需求分析: 從鍵盤輸入5名學員某門課程的筆試成績, 3  * 並求出五門成績的最高分、最低分和平均分 4  * @author chenyanlong 5  * 日期:2017/10/14 6  */ 7 package com.hp.test05; 8  9 import java.util.Scanner;10 11 public class HS_Array2 {12 13     public static void main(String[] args) {14         15         int[] scores=new int[5];16         int sum=0;17       18         double avg;19         System.out.println("請輸入5個成績");20         21         Scanner input=new Scanner(System.in);22         for(int i=0;i<scores.length;i++){           23             scores[i]=input.nextInt();24         }25         //總成績,最高分,最低分26         int max=scores[0];27         int min=scores[0];28         for(int j=0;j<scores.length;j++){29             //總成績30             sum +=scores[j];31             //最低分32             if(scores[j]<min){33                 min=scores[j];34             }35             //最低分36             if(scores[j]>max){37                 max=scores[j];38             }39         }40         avg=sum/scores.length;41         System.out.println("總成績:"+sum);42         System.out.println("最高分:"+max);43         System.out.println("最低分:"+min);44         System.out.println("平均分:"+avg);45             46     }47 }
 1 /** 2  * 需求分析: 用二維數組存放三個班學生的成績,並計算三個班學生的總成績     3  * @author chenyanlong 4  * 日期:2017/10/14 5  */ 6 package com.hp.test05; 7  8 import java.util.Arrays; 9 import java.util.Scanner;10 11 public class HS_Array3 {12 13     public static void main(String[] args) {14         15         int[][] array=new int[][]{{2,1},{2,1,3},{2,1}};16         for(int i=0;i<array.length;i++){17             String str=(i+1)+"班";18             Arrays.sort(array[i]);19             System.out.println(str+"排序以後");20             for(int j=0;j<array[i].length;j++){21                 System.out.println(array[i][j]);22             }23         }24     }25 }
 1 /** 2  * 需求分析: 用二維數組存放三個班學生的成績,並對三個班級學產生績進行排序 3  * @author chenyanlong 4  * 日期:2017/10/14 5  */ 6 package com.hp.test05; 7  8 import java.util.Scanner; 9 10 public class HS_Array4 {11 12     public static void main(String[] args) {13         14         int[][] array=new int[][]{{1,2},{1,2,3},{1,2}};15         16         for(int i=0;i<array.length;i++){17             String str=(i+1)+"班";18             int total=0;19             for(int j=0;j<array[i].length;j++){20                 total +=array[i][j];//成績匯總21             }22             System.out.println(str+"總成績:"+total);23         }24         25        26     }27 }

 

java程式碼範例(5)

聯繫我們

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