返回列表 發帖
  1. package site.istak.org.tw;

  2. import java.util.Scanner;

  3. public class Main {

  4.         public static void main(String[] args) {
  5.                
  6.                 Scanner scanner = new Scanner(System.in);
  7.                
  8.                 int[]StuA = new int [3];
  9.                
  10.                 int[]StuB = new int [3];
  11.                
  12.                 int[]StuC = new int [3];
  13.                
  14.                 for(int i=0;i<StuA.length;i++)
  15.                 {
  16.                         StuA[i] = scanner.nextInt();
  17.                        
  18.                 }
  19.                 for(int i=0;i<StuB.length;i++)
  20.                 {
  21.                         StuB[i] = scanner.nextInt();
  22.                        
  23.                 }
  24.                 for(int i=0;i<StuC.length;i++)
  25.                 {
  26.                         StuC[i] = scanner.nextInt();
  27.                        
  28.                 }
  29.                
  30.                 Stu stu = new Stu();
  31.                
  32.                 Stu.Avg(StuA[0],StuA[1],StuA[2]);
  33.                
  34.                 Stu.Avg(StuB[0],StuB[1],StuB[2]);
  35.                
  36.                 Stu.Avg(StuC[0],StuC[1],StuC[2]);
  37.                
  38.                
  39.         }

  40. }
複製代碼
  1. package site.istak.org.tw;

  2. public class Stu {
  3.        
  4.         private float Chinese;
  5.         private float English;
  6.         private float Math;
  7.         private float Total;
  8.        
  9.         public Stu(){
  10.                
  11.                 this.Chinese = Chinese;
  12.                 this.English = English;
  13.                 this.Math = Math;
  14.                                
  15.                
  16.         }
  17.        
  18.         public static void Avg(int Chinese , int English , int Math)
  19.         {
  20.                
  21.                 int total = Chinese + English + Math ;
  22.                 System.out.print(total / 3);
  23.         }

  24. }
複製代碼

TOP

返回列表