当我尝试返回对象数组时,为什么我在第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;
}
}
错误说:
必需:找到的值:class。
请帮我找出错误及其发生的原因。
答案 0 :(得分:2)
变化
Student[] splitarr = splitStudentArray(arr, char 'e');
到
Student[] splitarr = splitStudentArray(arr,'e');
调用方法时,不指定变量的类型(在您的情况下为char)。