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

  2. import java.util.Scanner;

  3. public class Main {

  4.         public static void main(String[] args) {
  5.                 Scanner scanner = new Scanner(System.in);
  6.                 int x[] = new int[3];
  7.                 int y[] = new int[3];
  8.                 int z[] = new int[3];
  9.                 System.out.print("小明成績:");
  10.                 for(int i=0;i<x.length;i++)
  11.                 {
  12.                         x[i] = scanner.nextInt();
  13.                 }
  14.                 System.out.print("小志成績:");
  15.                 for(int i=0;i<y.length;i++)
  16.                 {       
  17.                         y[i] = scanner.nextInt();
  18.                 }
  19.                 System.out.print("小美成績:");
  20.                 for(int i=0;i<z.length;i++)
  21.                 {       
  22.                         z[i] = scanner.nextInt();
  23.                 }
  24.                 Student stu = new Student();
  25.                 System.out.print("小明平均成績:");
  26.                 Student.average(x[0], x[1], x[2]);
  27.                 System.out.print("小志平均成績:");
  28.                 Student.average(y[0], y[1], y[2]);
  29.                 System.out.print("小美平均成績:");
  30.                 Student.average(z[0], z[1], z[2]);
  31.         }

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

  2. public class Student {
  3.         private static float total;
  4.         private static float c;
  5.         private static float e;
  6.         private static float m;
  7.         public void Student()
  8.         {
  9.                 this.c = c;
  10.                 this.e = e;
  11.                 this.m = m;
  12.                 this.total = total;
  13.         }
  14.         public static void average(int c,int e,int m)
  15.         {
  16.                 total = c+e+m;
  17.                 System.out.println(total/3);
  18.         }

  19. }
複製代碼

TOP

返回列表