gpt4 book ai didi

java - 构造函数声明中存在语法错误 : '{' expected

转载 作者:行者123 更新时间:2023-12-02 01:17:06 25 4
gpt4 key购买 nike

我不明白我对这个构造函数做错了什么:

  public class Student(String first_name, String last_name, int home1, int home2,int quiz1, int quiz2, int quiz3, int exam1, int exam2)
{
fname=first_name;
lname=last_name;
hw1_grade=home1;
hw2_grade=home2;
quiz1_grade=quiz1;
quiz2_grade=quiz2;
quiz3_grade=quiz3;
exam1_grade=exam1;
exam2_grade=exam2;
}

编译器说:需要“{”。另外:<标识符>预计它会一遍又一遍地显示此错误

最佳答案

public class Student {
private String fname;
private String lname;
private int hw1_grade;
private int hw2_grade;
private int quiz1_grade;
private int quiz2_grade;
private int quiz3_grade;
private int exam1_grade;
private int exam2_grade;

public Student(String first_name, String last_name, int home1, int home2, int quiz1, int quiz2, int quiz3,
int exam1, int exam2) {
fname = first_name;
lname = last_name;
hw1_grade = home1;
hw2_grade = home2;
quiz1_grade = quiz1;
quiz2_grade = quiz2;
quiz3_grade = quiz3;
exam1_grade = exam1;
exam2_grade = exam2;
}
}

关于java - 构造函数声明中存在语法错误 : '{' expected,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58382374/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com