Java 在while语句中实现计数
我正在编写一套代码,在每一个“回合”后(一个回合是当所有3匹马都离开时),阶段将上升1。然而,当我运行它并在最后输出阶段时,它总是返回为0。在这种情况下,实施阶段计数的最佳方法是什么Java 在while语句中实现计数,java,count,Java,Count,我正在编写一套代码,在每一个“回合”后(一个回合是当所有3匹马都离开时),阶段将上升1。然而,当我运行它并在最后输出阶段时,它总是返回为0。在这种情况下,实施阶段计数的最佳方法是什么 while (horse1.getLocation() <= 250 && horse2.getLocation() <= 250 && horse3.getLocation() <= 250){ int phase = 0; horse1.m
while (horse1.getLocation() <= 250 && horse2.getLocation() <= 250 && horse3.getLocation() <= 250){
int phase = 0;
horse1.move(phase);
horse2.move(phase);
horse3.move(phase);
horse1.location++;
horse2.location++;
horse3.location++;
phase++;
}
while(horse1.getLocation()更改为
int phase = 0;
while (horse1.getLocation() <= 250 && horse2.getLocation() <= 250 &&
horse3.getLocation() <= 250){
....
}
int-phase=0;
而(horse1.getLocation()更改为
int phase = 0;
while (horse1.getLocation() <= 250 && horse2.getLocation() <= 250 &&
horse3.getLocation() <= 250){
....
}
int-phase=0;
while(horse1.getLocation()在循环外移动int-phase=0;
。每次迭代都将其重置为0。在循环外移动int-phase=0;
。每次迭代都将其重置为0。新手错误。谢谢!新手错误。谢谢!