+ 1
Is anyway to introduce time in loop?
I want to introduce time in my loop, like for(i=1sec;i<=10sec;i++) anyway to implement this on a program. I want to count time and the total number of times. Any possible way. like say "Hello" in 5 times in an interval 2 sec. I know the above won't work tho😅. Any help
7 ответов
+ 3
try this:
the loop will print the current time once every 5 seconds:
try {
while (true) {
System.out.println(new Date());
Thread.sleep(5 * 1000);
}
} catch (InterruptedException e) {
e.printStackTrace();
}
+ 1
what you're looking for is a delay ( threads sleep ) function.
# talking about c++
Windows has "Sleep(miliseconds)"
Unix has "usleep(microseconds)"
https://code.sololearn.com/cwYuFn2WFeFH/?ref=app
you shouldn't run it from sololearn application.
0
error @Cain
0
Can you help me with a program to type "Hello" 10 times in a interval of 5 sec each
0
@Sabareesh A P I updated the function.