我有一个 while 循环,运行大约 1000 万次,每次都会递增变量“day”。我希望程序仅在一百万天过去后才打印一行(即
一百万天过去了
200万天过去了
...
循环完成
到目前为止我有代码:
double dayMill; //outside the loop
...
dayMill = day/1000000; //every runthrough of the loop
我正在考虑使用 if 语句与诸如此类的事情
if( (int)dayMill == dayMill){}
因为当 day = 1,000,000 时,daymill = 1,所以转换为 int 时它也是 1。然而这不起作用。它打印 0.0 万天...很多直到 1.0 很多...永远不会只是我想要的每一百万天的一行
最佳答案
if(dayMill % 1000000 == 0)
{
//print statement
}
也就是说,如果您将 dayMill 设置为 int。如果加一,为什么会是双倍?我想我不太明白你到底在做什么。
关于java - 循环中每百万次才执行一条语句,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13197806/