返回列表 發帖

陣列 (五) - 成績表

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


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

本帖最後由 張郁庭 於 2019-8-6 14:16 編輯
  1. public class Ch01
  2. {
  3.     public static void main(String args[])
  4.     {
  5.         String title[]={"座號","姓名","國文","英文","數學","平均"};
  6.         String name[]={"小叮噹","大雄","宜靜","技安","阿福"};
  7.         int score[][]={{84,95,78,0},
  8.                                {84,62,75,0},
  9.                                {75,65,84,0},
  10.                                {84,95,75,0},
  11.                                {64,65,74,89}};
  12.         for(int i=0; i<6; i++)
  13.                 System.out.print(title[i]+"\t");
  14.         System.out.println();
  15.         System.out.println("===========================================");
  16.         for(int i=0; i<5; i++)
  17.         {
  18.                 System.out.print((i+1)+"\t"+name[i]+"\t");
  19.                 for(int j=0; j<3; j++)
  20.                 {
  21.                         System.out.print(score[i][j]+"\t");
  22.                 }       
  23.                 float average=(float)((score[i][0]+score[i][1]+score[i][2])/3);
  24.                 System.out.println(Math.round(average));
  25.         }
  26.     }
  27. }
複製代碼

TOP

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

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.         for(int i=0; i<=5; i++)
  8.             System.out.print(title[i]+"\t");
  9.         System.out.print("\n===============================================\n");
  10.         for(int i=0; i<=4; i++)
  11.         {
  12.                 float avg;
  13.                 avg=(score[i][0]+score[i][1]+score[i][2])/3;
  14.                 avg=Math.round(avg);
  15.                 System.out.print(i+1+"\t"+name[i]+"\t");
  16.             for(int j=0; j<=2; j++)
  17.                     System.out.print(score[i][j]+"\t");
  18.             System.out.println((int)avg);
  19.         }
  20.     }
  21. }
複製代碼

TOP

  1. public class Ch24 {
  2.         public static void main(String[] args){
  3.                 String title[]={"座號","姓名","國文","英文","平均"};
  4.                 String name[]={"小叮噹","大雄","靜香","胖虎","小夫"};
  5.                 int score[][]={{78,87,56,0},{54,35,87,0},{65,54,87,0},{21,98,54,0}};
  6.                 for(int i=0;i<6;i++)
  7.                         System.out.print(title[i]+"\t");
  8.                 System.out.println();
  9.                 System.out.println("***********************************");
  10.                 for(int i=0;i<5;i++){
  11.                         score[i][3]=Math.round((float)(score[i][0]+score[i][1]+score[i][2])/3);
  12.                         System.out.print((i+1)+"\t"+name[i]+"\t");
  13.                         for(int j=0;j<4;j++)
  14.                                 System.out.print(score[i][j]+"\t");
  15.                         System.out.println();       
  16.                 }
  17.         }
  18. }
複製代碼

TOP

本帖最後由 潘憶承 於 2019-8-6 14:26 編輯
  1. public class Ch02
  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.                         {
  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 CH01
  2. {
  3.     public static void main(String args[])
  4.     {
  5.             String title[]={"座號","姓名","國文","英文","數學","平均"};
  6.             String name[]={"小叮噹","大雄","宜靜","技安","阿福"};
  7.             int score[][]={{99,100,96},{11,5,3},{91,89,95},{53,45,58},{77,78,82}};
  8.             float a;
  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.                 a=(float)(Math.round(score[i][0]+score[i][1]+score[i][2])/3);
  16.                 System.out.print((i+1)+"\t"+name[i]+"\t");
  17.                 for(int j=0;j<3;j++)
  18.                 {
  19.                 System.out.print(score[i][j]+"\t");
  20.                 }
  21.             System.out.println(a);               
  22.         }           
  23.     }
  24. }
複製代碼

TOP

  1. public class Ch10{
  2.         public static void main(String[]args)
  3.         {
  4.                 String title[]={"號","名","國","英","數","平均"};
  5.                 String name[]={"a","s","d","f","g","h"};
  6.                 int score[][]={{90,88,89},
  7.                                 {70,67,54},
  8.                                 {89,88,90},
  9.                                 {17,33,56},
  10.                                 {77,79,46}};
  11.                 for(int i=0; i<6;i++)
  12.                         System.out.print(title[i]+"\t");
  13.                 System.out.println("\n=============================================");
  14.                 for(int i=0; i<5;i++)
  15.                 {
  16.                         System.out.print((i+1)+"\t"+name[i]+"\t");
  17.                         for(int j=0; j<3; j++)
  18.                                 System.out.print(score[i][j]+"\t");
  19.                         float avg=(float)(score[i][0]+score[i][1]+score[i][2])/3;
  20.                         System.out.println(avg);
  21.                 }       
  22.         }
  23. }
複製代碼

TOP

  1. import java.util.Scanner;

  2. public class Ch11
  3. {
  4.         public static void main(String args[])
  5.         {String a[]={"座號","姓名","國文","英文","數學","平均"};
  6.         int s[]={1,2,3,4,5};
  7.         String n[]={"小叮噹","大雄","靜香","胖虎","小夫"};
  8.         int p[][]={
  9.                            {90,85,86},
  10.                            {70,75,80},
  11.                            {80,95,80},
  12.                            {70,95,75},
  13.                            {80,85,95}
  14.                   };
  15.         for( int i=0;i<6;i++)
  16.         {
  17.                 System.out.print(a[i]+"\t");
  18.         }
  19.         System.out.println();
  20.         System.out.println("===============================================================");
  21.         for(int i=0;i<5;i++)
  22.         {
  23.                 System.out.print(s[i]+"\t"+n[i]+"\t");
  24.                 for(int j=0;j<3;j++)
  25.                 {
  26.                         System.out.print(p[i][j]+"\t");
  27.                 }
  28.                 System.out.println(Math.round((p[i][0]+p[i][1]+p[i][2])/3)+"\t");
  29.         }

  30.   }


  31. }
複製代碼

TOP

本帖最後由 莊鈞程 於 2019-8-6 14:32 編輯
  1. import java.util.Scanner;
  2. public class Ch34 {
  3.         public static void main(String[] args){
  4.             String title[]={"座號","姓名","國文","英文","數學","平均"};
  5.             String name[]={"小叮噹","大雄","宜靜","技安","阿福"};
  6.             int score[][]={{84,54,87,0}
  7.                           ,{54,45,41,0}
  8.                           ,{54,78,97,0}
  9.                           ,{100,25,1,0}
  10.                           ,{64,78,60,0}};
  11.             for(int i=0;i<6;i++)
  12.                 System.out.print(title[i]+" \t");
  13.             System.out.println("\n============================================");
  14.             for(int i=0;i<5;i++){
  15.                     float avg=(float)(score[i][0]+score[i][1]+score[i][2])/3;
  16.                     System.out.print((i+1)+" \t"+name[i]+" \t");
  17.                     for(int j=0;j<3;j++)
  18.                             System.out.print(score[i][j]+" \t");
  19.                     System.out.println(avg);
  20.             }
  21.                     
  22.         }
  23. }
複製代碼

TOP

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

TOP

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

  20.         }
  21. }
複製代碼

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},{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.                                 System.out.print(score[i][j]+"\t");
  18.                         avg=Math.round((float)(score[i][0]+score[i][1]+score[i][2])/3);
  19.                         System.out.println(avg);
  20.                 }
  21.         }
  22. }
複製代碼

TOP

本帖最後由 余映均 於 2019-8-6 14:39 編輯
  1. public class Ch02 {

  2.         public static void main(String[] args) {
  3.         String title[]={"座號","姓名","國文","英文","數學","平均"};
  4.         String name[]={"小叮噹","大雄","宜靜","技安","阿福"};
  5.         int score[][]={{98,65,48},
  6.                                {97,85,96},
  7.                                {84,95,75},
  8.                                {65,85,60},
  9.                                {89,92,95}};
  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.                 avg=Math.round((float)(score[i][0]+score[i][1]+score[i][2])/3);
  18.                 System.out.print((i+1)+"\t"+name[i]+"\t");
  19.                 for(int j=0;j<3;j++)
  20.                     System.out.print(score[i][j]+"\t");
  21.                 System.out.println(avg);
  22.         }         
  23.         }
  24. }
複製代碼

TOP

  1. {  
  2.                 String title[]={"座號","姓名","國文","英文","數學","平均"};
  3.                 String name[]={"小叮噹","大雄","宜靜","技安","阿福"};
  4.                 int score[][]={{90,85,85},
  5.                                       {70,75,80},
  6.                                       {80,95,80},
  7.                                       {70,95,81},
  8.                                       {80,85,95}};
  9.                 for(int i=0; i<6; i++)
  10.                         System.out.print(title[i]+"\t");
  11.                 System.out.println("\n==================================================");
  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.                                 System.out.print(score[i][j]+"\t");
  17.                         float avg=(float)(score[i][0]+score[i][1]+score[i][2])/3;
  18.                         System.out.println(avg);
  19.                 }
  20.         }       
  21. }
複製代碼

TOP

返回列表