返回列表 發帖

陣列 (三)

本帖最後由 tonyh 於 2012-10-27 16:52 編輯

利用二維陣列, 試做一個包含五位同學, 各三組分數的成績表格.
表格的形式如下:
座號   國文  英文  數學  平均
==================
   1
   2
   3
   4
   5
  1. public class ch37
  2. {
  3.     public static void main(String args[])
  4.     {
  5.          float score[][]={{68,78,90,0},{55,70,78,0},{78,98,80,0},{35,56,55,0},{63,76,77,0}};
  6.          System.out.println("座號\t國文\t英文\t數學\t平均");
  7.          System.out.println("=========================================");
  8.          for(int i=0; i<=4; i++)
  9.          {
  10.              System.out.print((i+1)+"\t");
  11.              score[i][3]=(score[i][0]+score[i][1]+score[i][2])/3;
  12.              for(int j=0; j<=3; j++)
  13.              {
  14.                    System.out.print(score[i][j]+"\t");
  15.              }
  16.              System.out.println();
  17.          }
  18.     }
  19. }
複製代碼

返回列表