+ 1

Why does this not run in playground

public class Program { public static void main(String[] args) { for(int i=20;i>0;i--){ System.out.print("*"); TimeUnit.SECONDS.sleep(10); } } }

9th Apr 2017, 7:52 PM
satyam saurav
satyam saurav - avatar
2 Answers
+ 16
sleep() does run, but because of how the Playground works, your code has to complete its execution completely before you're sent back the end result. So on the server that's running your code, it is waiting. But if it takes too long to run, it's kicked off the server early. I'd recommend running the code on an offline compiler to see sleep() working correctly.
9th Apr 2017, 8:00 PM
Tamra
Tamra - avatar
+ 6
Also, your for loop is an infinite loop.
9th Apr 2017, 8:02 PM
Rrestoring faith
Rrestoring faith - avatar