public void removeDups() {
int i, k, j, lastFound = 0;
if (this.nElements < 1) {
System.out.println("Empty Array");
} else {
for (i = 0; i < this.nElements; i = lastFound) //outer loop
{
for (j = i + 1; j < this.nElements; j++) {
if (this.arr[i] == this.arr[j]) {
lastFound = i;
for (k = i; k < this.nElements; k++) {
this.arr[k] = this.arr[k + 1];
}
this.nElements--;
break;
}
}
}
for (i = 0; i < this.nElements; i++) {
System.out.println(this.arr[i]);
}
}
}
上一个方法从调用它的对象(数组)中删除重复项,问题是我希望外循环从每个增量的某个位置开始,我将该位置的值分配给变量 lastFound 并将该变量放入增量中循环的一部分,但程序进入无限循环并且永远不会停止,那有什么问题?