gpt4 book ai didi

java - 返回对象数组时出现意外类型错误

转载 作者:行者123 更新时间:2023-12-02 04:34:56 25 4
gpt4 key购买 nike

当我尝试返回对象数组时,为什么会在第 22 行收到意外的类型错误?

public class StudentDemo {
public static void main(String args[]){

StudentDemo program = new StudentDemo();
program.start();
}

public void start(){
Student one = new Student(1, "x", 80.0);
Student two = new Student(2, "y", 81.0);
Student three = new Student(3,"z", 79.5);
Student four = new Student(4, "a", 85.0);
Student five = new Student(5, "b", 86.0);
Student arr[] = {one,two,three,four,five};
Student[] splitarr = splitStudentArray(arr, char 'e'); //line 22
splitarr[0].getName();
}

public Student[] splitStudentArray(Student arr[], char choice){

Student[] splitArr = new Student[5];
if(choice == 'e'){

for(int i = 0; i<5; i++){
if(arr[i].getMarks()%2 == 0){
splitArr[i] = arr[i];
}
}
}

else if(choice == 'o'){

for(int i = 0; i<5; i++){
if(arr[i].getMarks()%2 != 0){
splitArr[i] = arr[i];
}
}
}

return splitArr;
}
}

错误提示:

required: value found: class.

请帮我找出错误及其发生原因。

最佳答案

改变

Student[] splitarr = splitStudentArray(arr, char 'e');

Student[] splitarr = splitStudentArray(arr,'e');

调用方法时,您没有指定变量的类型(在您的例子中为 char)。

关于java - 返回对象数组时出现意外类型错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30952904/

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