本帖最後由 tonyh 於 2014-7-12 14:41 編輯
針對上一個練習, 新增 "姓名" 與 "平均" 欄位.
- public class ch38
- {
- public static void main(String args[])
- {
- String name[]={"小叮噹","大雄","宜靜","技安","阿福"};
- int n[][]={{90,85,85,0},
- {70,75,80,0},
- {80,95,80,0},
- {70,95,75,0},
- {80,85,95,0}};
- System.out.println("座號\t姓名\t國文\t英文\t數學\t平均");
- System.out.println("=============================================");
- for(int i=0; i<5; i++)
- {
- n[i][3]=(n[i][0]+n[i][1]+n[i][2])/3;
- System.out.print((i+1)+"\t"+name[i]+"\t");
- for(int j=0; j<4; j++)
- {
- System.out.print(n[i][j]+"\t");
- }
- System.out.println();
- }
- }
- }
複製代碼 |