int MATCH_LENGTH = 0;
int FINAL_MATCH_LENGTH = 0;
int FINAL_MATCH_POS = 0;
while (window.contains(next)) {
int MATCH_POS = window.indexOf(next);
boolean nextMatches = true;
while (nextMatches = true) {
int index = window.indexOf(next);
index++;
int positionOfNext = fileArray.indexOf(next);
positionOfNext++;
MATCH_LENGTH++;
char afterNext = fileArray.get(positionOfNext);
char afterNextInWindow = window.get(index);
if (afterNext != afterNextInWindow) {
nextMatches = false;
if (MATCH_LENGTH > FINAL_MATCH_LENGTH) {
FINAL_MATCH_POS = MATCH_POS;
FINAL_MATCH_LENGTH = MATCH_LENGTH;
MATCH_LENGTH = 0;
}
window.remove(window.indexOf(next));
}
}
}
我在这里遇到了一个无限循环。我认为这是因为nextMatches
布尔变量。但是,我不确定这对程序有何影响,因为我的while
循环条件为while (window.contains(next))
. 但是,我将next
一一删除,因此最终while (window.contains(next))
将不得不返回 false 并且while
循环将不得不中断。尽管删除线,我的推理可能存在缺陷window.remove(window.indexOf(next));
。
还是我推理的其他部分有缺陷?