【发布时间】:2017-11-12 20:54:41
【问题描述】:
我只是想在提交我的作品之前确保我在下面编写的代码被正确翻译。该方法确实有效,但我觉得我可能写错了。
伪代码:
assign i the value 0
WHILE i is less than the length of the array minus 1
let bubbleI be the bubble at index i in the bubbles array
assign j the value i + 1
WHILE bubbleI is not popped AND j is less than the length of the bubbles
array
let bubbleJ be the bubble at index j in the bubbles array
IF bubbleJ is not popped AND bubbleI is touching bubbleJ
pop both bubbleI and bubbleJ
END IF
increment j by 1
END WHILE
increment i by 1
END WHILE
我的代码:
private void popAll() {
int i = 0;
while (i < bubbles.length - 1){
bubbles[i] = bubbles[i];
int j = i + 1;
while (bubbles[i].isPopped() == false && j < bubbles.length){
bubbles[j] = bubbles[j];
if (bubbles[j].isPopped() == false && bubbles[i].isTouching(bubbles[j]) == true){
bubbles[i].pop();
bubbles[j].pop();
}
j++;
}
i++;
}
}
【问题讨论】:
标签: java loops methods parameters