0

How can i do a program than print seconds each second

7th Sep 2017, 1:24 AM
Brandon Jesús Hernández Herrera
Brandon Jesús Hernández Herrera - avatar
3 Respuestas
+ 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(); } } } }
7th Sep 2017, 1:55 AM
ChaoticDawg
ChaoticDawg - avatar
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
7th Sep 2017, 1:44 AM
Testing003