如何在Java中延遲?我正在嘗試用Java做一些事情,我需要一些東西來等待/延遲幾秒鐘,在WITH循環(huán)中。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條經(jīng)驗 獲得超0個贊
Thread.sleep(1000)
;
1000
try{ Thread.sleep(1000);}catch(InterruptedException ex){ Thread.currentThread().interrupt();}

慕桂英3389331
TA貢獻2036條經(jīng)驗 獲得超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
提交
取消