my while loop:
while (j =>0&& (courseArray[j].compareByCourse(value)) >=0 ){
}
在netbeans中给我这个错误:int cannot be converted to boolean
方法:
public static void insertionSort(Course[] courseArray){
Course value ; // the next value from the unsorted list to be inserted into the sorted list
int i; // i is a pointer to an item in the unsorted list
int j; // j is a pointer to an item in the sorted list; originally the sorted list is just a[0]
int compare;
for (i=1; i<courseArray.length; i++){
value = courseArray[i];
j = i -1;
compare = courseArray[j].compareByCourse(value);
while (j =>0&& (courseArray[j].compareByCourse(value)) >=0 ){
}
}
}
compareByCourse方法:
//method to compare Courses by course name
int compareByCourse(Course other){
return this.course.compareTo(other.getCourse());
}
j
是int
,返回值是int
, 0
是int
,那么布尔值在哪里?
似乎您混淆了操作符>=
与=>
(这不是Java中的有效操作符)。尝试将while条件更改为:
while (j >= 0 && (courseArray[j].compareByCourse(value)) >= 0 )
如果你将j
赋值给:
compare = courseArray[j].compareByCourse(value);
在while循环中使用(也可以直接使用)