public static void main(String[] args) {
var time = 10;
var queue = new LinkedList<>();
for(var i = time;i>0;i--)
queue.add(i);
while(!queue.isEmpty()) {
System.out.print(queue.remove()+"");
try {
Thread.sleep(1000);
}catch(InterruptedException e) {
e.printStackTrace();
}
}
}
能不能给这个JAVA添加一下注释
- 写回答
- 好问题 0 提建议
- 关注问题
- 邀请回答
-
2条回答 默认 最新
it_hao528 2022-11-09 18:52关注var time = 10; // 定义一个变量time赋值为10 var queue = new LinkedList<>(); // 定义一个LinkedList对象 queue for(var i = time;i>0;i--) queue.add(i); // 循环给queue添加元素 while(!queue.isEmpty()) { // queue不为空则进入while循环 System.out.print(queue.remove()+""); // 输出 queue 移除的元素 try { Thread.sleep(1000); // 线程停止1秒 }catch(InterruptedException e) { e.printStackTrace(); // 输出异常 } }本回答被题主选为最佳回答 , 对您是否有帮助呢?评论 打赏 举报解决 1无用