+ 1
Delay in countown
I'm trying to do a countown using this program and I want to add some time delay between a number and the next. Right now it says all the numbers at once. int x=100; while(x>0) System.out.println(--x); Thank you.
4 Answers
+ 3
You can use
Thread.sleep(milliseconds);
However, this wil not work in the SoloLearn playground due to it giving all the output at once. You can run it on your own computer or in another interactive online compiler such as
https://www.tutorialspoint.com/compile_java8_online.php.
import java.lang.Thread;
...
int x = 100;
while (x > 0) {
Thread.sleep(1000); // 1 second
System.out.println(--x);
}
...
+ 1
No, unfortunately not with the limitations of the playground.
+ 1
I will try with other platform then.
0
Isn't any form of doing it here then? Thanks for helping.