我正在开发一个永远运行的Java程序,但我不知道如何在不使用“try catch”的情况下将每个循环延迟一秒钟。我试过了
import java.util.concurrent.TimeUnit;
public class program {
public static void main(String[] args) {
TimeUnit wait = new TimeUnit();
while (true) {
wait.SECONDS.sleep(1);
}
}
}
Run Code Online (Sandbox Code Playgroud)
但这似乎不起作用。谁能帮我?