
ï??Using for loops, Write a program to simulate a clock countdown. The program prompts the user to enter the number of seconds, displays a message at every second, and terminates when the time expires. Use method System.currentTimeMillis() which return the number of milliseconds since the epoch (which is midnight Jan 1st 1970 UTC).

import java.util.*;
class clock
{
public static void main(String args[])
{
Scanner input=new Scanner(System.in);
System.out.print("Enter number of seconds: ");
int s = input.nextInt();
long milliseconds=System.currentTimeMillis();
Calendar cal=new GregorianCalendar();
cal.setTimeInMillis(milliseconds) ;
int hour = cal.get(Calendar.HOUR);
int minutes = cal.get(Calendar.MINUTE);
int sec=0;
for(sec=0;sec<=s;sec++){
System.out.print(hour+":"+ minutes+":"+sec);
try{
Thread.sleep(1000);
System.out.print("\r");
}
catch(Exception e){}
}
}
}
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.