每 X 秒打印“你好世界”
最近我一直在使用带有大数字的循环来打印出来:Hello World
int counter = 0;
while(true) {
//loop for ~5 seconds
for(int i = 0; i < 2147483647 ; i++) {
//another loop because it's 2012 and PCs have gotten considerably faster :)
for(int j = 0; j < 2147483647 ; j++){ ... }
}
System.out.println(counter + ". Hello World!");
counter++;
}
我知道这是一种非常愚蠢的方法,但我从未在Java中使用过任何计时器库。如何修改上述内容以每说3秒打印一次?