0
How can i do a program than print seconds each second
3 Answers
+ 3
Are you wanting to print the system clocks seconds, or just print out a second count every second? The code below will print out a count every second (1000 milliseconds) for ten seconds. Note that it won't really work here in the code playground (neither will printing the system clocks seconds) as there is a limit to how long your code can run and the output is printed after the code has finished running. It will be best to run this type of code on your own computer.
public class Program
{
public static void main(String[] args) {
for(int i = 1; i < 11; ++i) {
System.out.println(i);
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}
0
in what language? what OS? for example if your language is c++ there are different ways of doing it depending on the OS. But there Is a workaeound for making it cross platform; here the link: https://stackoverflow.com/questions/10918206/cross-platform-sleep-function-for-c