返回列表 發帖

陣列 (五) - 成績表

利用二維陣列, 試做一個包含五位同學, 各三組分數的成績表格.
表格的形式如下:


本帖隱藏的內容需要回復才可以瀏覽

  1. public class Ch01 {
  2.         public static void main(String[] args)
  3.         {
  4.                 int a[]={1,2,3,4}
  5.                 int b[][]={{1,2,3,4},{1,2,3,4},{1,2,3,4}};
  6.                 int c[][][]={{{1,2,3,4},{1,2,3,4},{1,2,3,4},{1,2,3,4},{1,2,3,4},{1,2,3,4}}}
  7.                 System.out.println(a.length);     //4
  8.                 System.out.println(b.length);     //3
  9.                 System.out.println(c.length);     //2
  10.         }
  11. }        
複製代碼

TOP

  1. import java.util.Scanner;
  2. public class Ch01 {
  3.         public static void main(String[] args)
  4.         {       
  5.                 String title[]={"座號","姓名","國文","英文","數學","平均"};
  6.                 String name[]={"小叮噹","大雄","宜靜","技安","阿福"};
  7.                 int score[][]={{90,85,85},
  8.                                 {70,75,80},
  9.                                 {80,95,80},
  10.                                 {70,95,75},
  11.                                 {80,85,92}};
  12.                 int avg;
  13.                 for(int i=0;i<6;i++)
  14.                         System.out.print(title[i]+"\t");
  15.                 System.out.println();
  16.                 System.out.println("===========================================");
  17.                 for(int i=0;i<4;i++)
  18.                 {
  19.                         System.out.print((i+1)+"\t"+name[i]+"\t");
  20.                         for(int j=0;j<3;j++)
  21.                                 System.out.print(score[i][j]+"\t");
  22.                         avg=(score[i][0]+score[i][1]+score[i][2])/3;
  23.                         System.out.println(avg);
  24.                 }
  25.         }
  26. }
複製代碼

TOP

  1. public class A01 {

  2.         public static void main(String[] args) {
  3.                 String Title[]={"座號","姓名","國文","英文","數學","平均"};
  4.                 for(int i=0; i<6; i++)
  5.                         System.out.print(Title[i]+"\t");
  6.                 System.out.println();
  7.                 for(int i=0; i<44; i++)
  8.                         System.out.print("=");
  9.                 System.out.println();
  10.                
  11.                 String Person[][]={{"1","2","3","4","5"},{"甲","乙","丙","丁","戊"}};
  12.                 int Score[][]={{90,70,80,70,80},{85,75,95,95,85},{85,80,80,75,95}};
  13.                 for(int j=0; j<5; j+=1){
  14.                         for(int k=0; k<2; k+=1)
  15.                                 System.out.print(Person[k][j]+"\t");
  16.                         for(int l=0; l<3; l+=1)
  17.                                 System.out.print(Score[l][j]+"\t");
  18.                         System.out.print((Score[0][j]+Score[1][j]+Score[2][j])/3);
  19.                         System.out.println();
  20.                 }
  21.         }

  22. }
複製代碼

TOP

  1. public class Ch01
  2. {
  3.         public static void main(String args[])
  4.         {
  5.                 String title[]={"座號","姓名","國文","英文","數學","平均"};
  6.                 String name[]={"多拉A夢","多拉B夢","多拉C夢","多拉D夢","多拉E夢"};
  7.                 int score[][]={{78,89,66},
  8.                                 {77,67,34},
  9.                                 {90,98,91},
  10.                                 {57,59,81},
  11.                                 {45,66,92}};
  12.                 int avg;
  13.                 for(int i=0; i<6; i++)
  14.                         System.out.print(title[i]+"\t");
  15.                 System.out.println();
  16.                 System.out.println("===========================================");
  17.                 for(int i=0; i<5; i++)
  18.                 {
  19.                         System.out.print((i+1)+"\t"+name[i]+"\t");
  20.                         for(int j=0; j<3; j++)
  21.                         {
  22.                                 System.out.print(score[i][j]+"\t");
  23.                         }
  24.                         avg=Math.round((float)(score[i][0]+score[i][1]+score[i][2])/3);
  25.                         System.out.println(avg);
  26.                 }

  27.         }
  28. }
複製代碼

TOP

  1. public class Ch03
  2. {
  3.         public static void main(String[] args)
  4.         {
  5.                 int avg;
  6.                 String a[]={"座號","姓名","國文","英文","數學","平均"};
  7.                 String b[]={"小叮噹","大雄","宜靜","技安","阿福"};
  8.                 int c[][]={{90,85,85},
  9.                                    {70,75,80},
  10.                                    {80,95,80},
  11.                                    {70,95,75},
  12.                                    {80,85,95}};
  13.                 for(int i=0; i<=5; i++)
  14.             System.out.print(a[i]+"\t");
  15.                 System.out.println();
  16.                 System.out.println("=========================================================");
  17.                 for(int i=0; i<=4; i++)
  18.                 {
  19.                         System.out.print((i+1)+"\t"+b[i]+"\t");
  20.                         for(int j=0; j<3; j++)
  21.                             System.out.print(c[i][j]+"\t");
  22.                         avg=(c[i][0]+c[i][1]+c[i][2])/3;
  23.                         System.out.println(avg);
  24.                 }
  25.         }

  26. }
複製代碼

TOP

  1. public class Ch05
  2. {
  3.         public static void main(String[] args)
  4.         {
  5.                 String title[]={"座號","姓名","國文","英文","數學","平均"};
  6.                 String name[]={"小叮噹","大雄","宜靜","技安","阿福"};
  7.                 int score[][]={{90,85,85},{70,75,80},{80,95,80},{70,95,75},{80,85,95}};
  8.                 int avg;
  9.                 for(int i=0;i<6;i++)
  10.                         System.out.print(title[i]+"\t");
  11.                 System.out.println();
  12.                 System.out.println("===========================================");
  13.                 for(int i=0;i<5;i++)
  14.                 {
  15.                         System.out.print((i+1)+"\t"+name[i]+"\t");
  16.                         for(int j=0;j<3;j++)
  17.                         {
  18.                                 System.out.print(score[i][j]+"\t");                       
  19.                         }
  20.                         avg=Math.round((float)(score[i][0]+score[i][1]+score[i][2])/3);
  21.                         System.out.println(avg);
  22.                 }
  23.         }
  24. }
複製代碼

TOP

  1. public class Ch07
  2. {
  3.         public static void main(String[] args)
  4.         {
  5.                 String  title[]={"座號","姓名","國文","英文","數學","平均"};
  6.                 String         name[]={"小叮噹","大熊","怡靜","濟安","阿福"};
  7.                 int score [][]={{78,89,66}
  8.                 ,{77,67,34}
  9.                 ,{90,98,91}
  10.                 ,{57,59,81}
  11.                 ,{45,66,92}};
  12.                 int avg;
  13.                 for(int i=0;i<6;i++)
  14.                         System.out.print(title[i]+"\t");
  15.                 System.out.println();
  16.                 System.out.println("======================================================");
  17.                 for(int i=0;i<5;i++)
  18.                 {
  19.                         System.out.print((i+1)+"\t"+name[i]+"\t");
  20.                         for(int j=0;j<3;j++)
  21.                                 System.out.print(score[i][j]+"\t");
  22.                         avg=Math.round((float)((score[i][0]+score[i][1]+score[i][2])/3));
  23.                         System.out.println(avg);
  24.                 }
  25.         }
  26. }
複製代碼

TOP

  1. public class Ch01 {
  2.         public static void main(String[] args)
  3.         {
  4.                 String title[]={"座號","姓名","國文","英文","數學","平均"};
  5.                 String name[]={"小叮噹","大雄","宜靜","技安","阿福"};
  6.                 int score[][]={{90,85,85},{70,75,80},{80,95,80},{70,95,75},{80,85,95}};
  7.                 int avg;
  8.                 for(int i=0; i<6; i++)
  9.                         System.out.print(title[i]+"\t");
  10.                 System.out.println();
  11.                 System.out.println("============================================================");
  12.                 for(int i=0;i<5; i++)
  13.                 {
  14.                         System.out.print((i+1)+"\t"+name[i]+"\t");
  15.                         for(int j=0; j<3; j++)
  16.                         {
  17.                                 System.out.print(score[i][j]+"\t");
  18.                         }
  19.                         avg=Math.round((float)(score[i][0])+score[i][1]+score[i][2])/3);
  20.                         System.out.println(avg);
  21.                        
  22.                 }
  23.         }
  24.         
複製代碼

TOP

  1. public class dd {

  2.         public static void main(String[] args) {
  3.                 String tittle[]={"座號","姓名","國文","英文","數學","平均"};
  4.                 String name[]={"小叮噹","大雄","宜靜","技安","阿福"};
  5.                 int score[][]={
  6.                                 {78,89,66},{77,67,34},{90,98,91},{57,59,81},{45,66,92}};
  7.                 int avg;
  8.                 for(int i=0; i<6; i++)
  9.                         System.out.print(tittle[i]+"\t");
  10.                 System.out.println();
  11.                 System.out.println("=================================================");
  12.                 for(int i=0;i<5;i++)
  13.                 {
  14.                         System.out.print((i+1)+"\t"+name[i]+"\t");
  15.                         for(int j=0;j<3;j++)
  16.                         {
  17.                                 System.out.print(score[i][j]+"\t");
  18.                         }
  19.                         avg=Math.round((float)(score[i][0]+score[i][1]+score[i][2])/3);
  20.                         System.out.println(avg);
  21.                 }
  22.         }

  23. }
複製代碼

TOP

  1. public class Ch11
  2. {
  3.        
  4.         public static void main(String[] args)
  5.         {
  6.                 String title[]={"座號","姓名","國文","英文","數學","平均"};
  7.                 String name[]={"小叮噹","大雄","宜靜","技安","阿福"};
  8.                 int score[][]={{90,85,85},
  9.                                {70,75,80},
  10.                                {80,95,80},
  11.                                {70,95,75},
  12.                                {80,85,95}};
  13.                 int avg;
  14.                 for(int i=0;i<6;i++)
  15.                         System.out.print(title[i]+"\t");
  16.                 System.out.println("\n===========================================");
  17.                 for(int i=0;i<5;i++)
  18.                 {
  19.                         System.out.print((i+1)+"\t"+name[i]+"\t");
  20.                         for(int j=0;j<3;j++)
  21.                                 System.out.print(score[i][j]+"\t");
  22.                         avg=(score[i][0]+score[i][1]+score[i][2])/3;
  23.                         System.out.println(avg);
  24.                 }
  25.         }
  26. }
  27.        
複製代碼

TOP

  1. public class Ch07 {
  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. }
複製代碼

TOP

返回列表