用java写一个倒计时10秒的代码
时间: 2023-03-12 14:19:53 浏览: 148
public class CountDownTimer {
public static void main(String[] args) {
int seconds = 10;
for (int i = seconds; i >= 0; i--) {
System.out.println(i);
try {
Thread.sleep(1000);
} catch (InterruptedException ex) {
Thread.currentThread().interrupt();
}
}
}
}我可以用Java编写一个倒计时10秒的代码:
public class CountDownTimer {
public static void main(String[] args) {
int seconds = 10;
for (int i = seconds; i >= 0; i--) {
System.out.println(i);
try {
Thread.sleep(1000);
} catch (InterruptedException ex) {
Thread.currentThread().interrupt();
}
}
}
}
阅读全文