Board logo

標題: 陣列 (五) - 成績表 [打印本頁]

作者: 李泳霖    時間: 2022-1-27 11:59     標題: 陣列 (五) - 成績表

本帖最後由 李泳霖 於 2022-1-27 15:10 編輯

利用二維陣列, 試做一個包含五位同學, 各三組分數的成績表格.
表格的形式如下:
  1. [code]public class Ch31 {
  2.     public static void main(String[] args) {
  3.         String title[]={"座號","姓名","國文","英文","數學","平均"};
  4.         String name[]={"小叮噹","大雄","宜靜","技安","阿福"};
  5.         int score[][]={{78,89,66},
  6.                        {77,67,34},
  7.                        {90,98,91},
  8.                        {57,59,81},
  9.                        {45,66,92}};
  10.         int avg;
  11.         for(int i=0; i<6; i++)
  12.             System.out.print(title[i]+"\t");
  13.         System.out.println();
  14.         System.out.println("===========================================");
  15.         for(int i=0; i<5; i++)
  16.         {
  17.             System.out.print((i+1)+"\t"+name[i]+"\t");
  18.             for(int j=0; j<3; j++)
  19.             {
  20.                 System.out.print(score[i][j]+"\t");
  21.             }
  22.             avg=Math.round((float)(score[i][0]+score[i][1]+score[i][2])/3);
  23.             System.out.println(avg);
  24.         }
  25.     }
  26. }
複製代碼
  1. public class Ch31 {
  2.     public static void main(String[] args) {
  3.         String title[]={"座號","姓名","國文","英文","數學","平均"};
  4.         String name[]={"小叮噹","大雄","宜靜","技安","阿福"};
  5.         int score[][]={{78,89,66,0},
  6.                        {77,67,34,0},
  7.                        {90,98,91,0},
  8.                        {57,59,81,0},
  9.                        {45,66,92,0}};
  10.         for(int i=0; i<6; i++)
  11.             System.out.print(title[i]+"\t");
  12.         System.out.println();
  13.         System.out.println("============================================");
  14.         for(int i=0; i<5; i++)
  15.         {
  16.             score[i][3]=Math.round((float)(score[i][0]+score[i][1]+score[i][2])/3);
  17.             System.out.print((i+1)+"\t"+name[i]+"\t");
  18.             for(int j=0; j<4; j++)
  19.                 System.out.print(score[i][j]+"\t");
  20.             System.out.println();
  21.         }
  22.     }
  23. }
複製代碼
[/code]
作者: 丁肇志    時間: 2022-1-27 13:03

此帖僅作者可見
作者: 曾俊儒    時間: 2022-1-27 13:33

此帖僅作者可見
作者: 趙彥傑    時間: 2022-1-27 14:13

此帖僅作者可見
作者: 許鈞彥    時間: 2022-1-27 15:00

此帖僅作者可見
作者: 于棋安    時間: 2022-1-27 15:09

此帖僅作者可見
作者: 宗翰    時間: 2022-1-27 15:17

此帖僅作者可見




歡迎光臨 種子論壇 | 高雄市資訊培育協會學員討論區 (http://istak.org.tw/seed/) Powered by Discuz! 7.2