我的while循环:
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
,那么布尔值在哪里?
答案 0 :(得分:2)
您似乎已将操作符>=
与=>
(在Java中不是有效的运算符)混淆了。尝试将while条件更改为:
while (j >= 0 && (courseArray[j].compareByCourse(value)) >= 0 )
此外,如果您要将j
分配给:
compare = courseArray[j].compareByCourse(value);
在while循环中使用它(你也可以直接使用它)。