您的当前位置:首页正文

Java:有五个学生,每个学生有3门课的成绩,从键盘输入以上数据(包括 学生号,姓名,三门课成绩) 要求:计算出平均成绩。

2024-12-01 来源:个人技术集锦
import java.util.Scanner;
public class Test {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);

        for (int i = 1;i < 6;i++){
            System.out.println("请输入第"+i+"名学生的数据");
            Student l = new Student();
            System.out.println("请输入学生学号:");
            l.sId = input.nextInt();
            System.out.println("请输入学生姓名:");
            l.name = input.next();
            System.out.println("请输入学生第一门课程成绩:");
            l.Grade1 = input.nextInt();
            System.out.println("请输入学生第二门课程成绩:");
            l.Grade2 = input.nextInt();
            System.out.println("请输入学生第三门课程成绩:");
            l.Grade3 = input.nextInt();
            System.out.println(l.average(l.Grade1, l.Grade3, l.Grade2));
        }
    }
}
class Student{
    int sId;
    String name;
    int Grade1;
    int Grade3;
    int Grade2;

    public Student(){

    }

    public int getsId() {
        return sId;
    }

    public void setsId(int sId) {
        this.sId = sId;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getGrade1() {
        return Grade1;
    }

    public void setGrade1(int grade1) {
        this.Grade1 = grade1;
    }

    public int getGrade3() {
        return Grade3;
    }

    public void setGrade3(int grade3) {
        this.Grade3 = grade3;
    }

    public  int getGrade2() {
        return Grade2;
    }

    public void setGrade2(int grade2) {
        this.Grade2 = grade2;
    }

    public double average(int Grade1, int Grade2, int Grade3){
        double v = (Grade1 + Grade2 + Grade3) / 3;
        return v;
    }
}
显示全文