Java Netbeans告诉我,当值是int时,它是布尔值
我的while循环:Java Netbeans告诉我,当值是int时,它是布尔值,java,netbeans,Java,Netbeans,我的while循环: while (j =>0&& (courseArray[j].compareByCourse(value)) >=0 ){ } 在netbeans中出现以下错误:int无法转换为布尔值 方法: public static void insertionSort(Course[] courseArray){ Course value ; // the next value from the unsorted list to be i
while (j =>0&& (courseArray[j].compareByCourse(value)) >=0 ){
}
在netbeans中出现以下错误:int无法转换为布尔值
方法:
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 ){
}
}
}
j
是一个int
,返回值是一个int
,0
是一个int
,那么布尔值在哪里呢?看起来你把操作符=
和
混淆了(在Java中它不是有效的操作符)。尝试将while条件更改为:
while (j >= 0 && (courseArray[j].compareByCourse(value)) >= 0 )
如果您正在将j
分配给:
compare = courseArray[j].compareByCourse(value);
在while循环中使用它(你也可以直接使用它)。什么是j=>0
应该是什么?呃,从=>
操作符开始是什么?解释一下=>
是什么就可以了。噢,哇。我觉得自己很愚蠢。我想去掉比较变量。我用它试图找出我做错了什么。@devnull对不起,=>
在Java中是有效的运算符吗?“我真的不知道它是什么。”克里斯蒂安,我这样问是因为你的回答似乎表明它是某个操作员。
compare = courseArray[j].compareByCourse(value);