- package site.istak.org.tw;
- import java.util.Scanner;
- public class Main {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- int x[] = new int[3];
- int y[] = new int[3];
- int z[] = new int[3];
- System.out.print("小明成績:");
- for(int i=0;i<x.length;i++)
- {
- x[i] = scanner.nextInt();
- }
- System.out.print("小志成績:");
- for(int i=0;i<y.length;i++)
- {
- y[i] = scanner.nextInt();
- }
- System.out.print("小美成績:");
- for(int i=0;i<z.length;i++)
- {
- z[i] = scanner.nextInt();
- }
- Student stu = new Student();
- System.out.print("小明平均成績:");
- Student.average(x[0], x[1], x[2]);
- System.out.print("小志平均成績:");
- Student.average(y[0], y[1], y[2]);
- System.out.print("小美平均成績:");
- Student.average(z[0], z[1], z[2]);
- }
- }
複製代碼- package site.istak.org.tw;
- public class Student {
- private static float total;
- private static float c;
- private static float e;
- private static float m;
- public void Student()
- {
- this.c = c;
- this.e = e;
- this.m = m;
- this.total = total;
- }
- public static void average(int c,int e,int m)
- {
- total = c+e+m;
- System.out.println(total/3);
- }
- }
複製代碼 |