Wednesday, June 28, 2017

CountDown Timer

Tags

Code:


class Timer implements Runnable{
Thread t;

int n;

public Timer(int x) {
t=new Thread(this);
n=x;
}


public void run() {
for(int i=n;i>0;i--) {
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
System.out.println("Error: "+e);
}
System.out.println(i);
}

}

}
public class CountDown {


public static void main(String[] args) {
System.out.println("--Main Started--");

Timer t=new Timer(10);
t.t.start();
try {
t.t.join();
}catch(Exception e) {
System.out.println(e);
}


System.out.println("Happy New Year\n--Main Finished--");
}

}

Output: