我在以下位置收到错误:
if (this.words[j].compareTo(this.words[minIdx]) < 0这种方法的。
private void sort() {
int minIdx;
Word temp;
this.shrink();
for (int i = 0; i < this.words.length; i++) {
minIdx = i;
for (int j = i+1;
j < this.words.length;
j++) {
if (this.words[j].compareTo(this.words[minIdx]) < 0) {
minIdx = j ;
}
}
temp = this.words[minIdx];
this.words[minIdx] = this.words[i];
this.words[i] = temp;
}
}我相信是因为我的心理咨询方法
private void shrink()
{
Word[] randomWords = new Word[aWordCount];
for (int i=0; i < uniqueWordCount;i++)
{
randomWords[i]=words[i];
}
words=randomWords;
}谁能给我指个方向?
发布于 2013-11-23 04:45:54
正如我在评论中所说的,它可以是任何东西;我们真的需要看到完整的代码和一些输入才能确定。
但是:
private void shrink()
{
Word[] randomWords = new Word[this.words.length];
for (int i=0; i < this.words.length;i++)
{
randomWords[i]=words[i];
}
words=randomWords;
}换句话说,确保您没有用可能有其他长度的数组替换第一个数组(并且后面可能有空项)。
https://stackoverflow.com/questions/20153988
复制相似问题