+ 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); } } }
2 Respuestas
+ 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.
+ 6
Also, your for loop is an infinite loop.