Anda di halaman 1dari 1

menghitung waktu mundur untuk 10 detik

public class CountDown implements Runnable{


private static int startCount = 11;
private int countDown = --startCount;
private static int threadCount = 0;
private int threadNumber = ++threadCount;
public void run() {
System.out.println("Waktu tinggal "+countDown+" detik ( Thread nomer : "+threadN
umber+" )");
if (countDown == 1) {
System.out.println("\nWaktu Habis ~ !!");
}
}
private static void doThreadCountdown() throws java.lang.InterruptedException{
for (int i = 0; i < 10; i++){
Thread.sleep(1000);
Runnable ot = new CountDown();
Thread th = new Thread(ot);
th.start();
}
}
public static void main(String[] args) throws java.lang.InterruptedException{
System.out.println("\nMenghitung mundur dalam 10 detik ...\n");
doThreadCountdown();
}
}

Anda mungkin juga menyukai