Netbeans告诉我,当它是一个int时,一个值是boolean

时间:2014-03-18 05:42:39

标签: java netbeans

我的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());
}

jint,返回值是int0int,那么布尔值在哪里?

1 个答案:

答案 0 :(得分:2)

您似乎已将操作符>==> (在Java中不是有效的运算符)混淆了。尝试将while条件更改为:

while (j >= 0 && (courseArray[j].compareByCourse(value)) >= 0 )

此外,如果您要将j分配给:

compare = courseArray[j].compareByCourse(value);

在while循环中使用它(你也可以直接使用它)。