do while 循环将执行 30 秒的持续时间。因为我必须每 5 秒打印一次当前日期......为此,我编写了如下代码。但它没有按预期工作......
public static void main(String[] args) {
long startTime = System.currentTimeMillis();
long duration = (30 * 1000);
do {
while (true) {
try {
System.out.println(" Date: " + new Date());
Thread.sleep(2 * 1000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
} while ((System.currentTimeMillis() - startTime) < duration);
}
浮云间
小唯快跑啊
当年话下
相关分类