package pojo;
public class time {
public static void main(String[] args) throws InterruptedException {
time.get();
}
public static void get() throws InterruptedException {
int num=20;
while (true){
Thread.sleep(1000);
System.out.println(num--);
if(num==0) {
break;
}
}
}
}
结果
该篇博客展示了如何在Java中使用`Thread.sleep()`方法实现线程暂停,并通过一个无限循环来打印并递减一个计数器,直到计数器为0时退出循环。这个例子体现了线程同步和循环控制的基本概念。
833

被折叠的 条评论
为什么被折叠?



