java为什么这个循环打印1020之间的所有值?我想让它打印出可以被5整除的值
int z=10;
int x=5;
boolean t= ((z % x) == 0);
while ( t && (z < 21))
{
s +=String.format("%8d", z)+this.mp.outstandingAfter(z, "%16.0f");
s+= "\n\n";
z++;
}
我希望它打印第10、15和20个值,但它打印的是10-20之间的所有值。我不明白为什么
# 1 楼答案
你的
t
永远不会改变,事实上也不一定会改变,因为你可以在每次迭代中检查条件是否为真