【发布时间】:2015-06-20 10:24:40
【问题描述】:
当我尝试返回对象数组时,为什么会在第 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;
}
}
错误提示:
必需:找到的值:类。
请帮助我找出错误及其发生的原因。
【问题讨论】: