如何在Java中延迟?我正在尝试用Java做一些事情,我需要一些东西来等待/延迟几秒钟,在WITH循环中。while (true) {
if (i == 3) {
i = 0;
}
ceva[i].setSelected(true);
// I need to wait here
ceva[i].setSelected(false);
// I need to wait here
i++;}我想构建一个步骤排序器,我对Java很陌生。有什么建议吗?
3 回答
catspeake
TA贡献1111条经验 获得超0个赞
Thread.sleep(1000)
;
1000
try{ Thread.sleep(1000);}catch(InterruptedException ex){ Thread.currentThread().interrupt();}
慕桂英3389331
TA贡献2036条经验 获得超8个赞
Thread.sleep(100);
public class SleepMessages { public static void main(String args[]) throws InterruptedException { String importantInfo[] = { "Mares eat oats", "Does eat oats", "Little lambs eat ivy", "A kid will eat ivy too" }; for (int i = 0; i < importantInfo.length; i++) { //Pause for 4 seconds Thread.sleep(4000); //Print a message System.out.println(importantInfo[i]); } }}
添加回答
举报
0/150
提交
取消