Countdown

  • 2
  • Locked
We're all for peace and fighting terrorism, but we'll write a countdown program just the same. Our program should count from 30 to 0 and then end with a "Boom!". Don't worry. The "Boom!" will be peaceful, silent text. The program should advance the countdown 10 times per second. To add a delay to the program, use Thread.sleep(100);
You can't complete this task, because you're not signed in.
Comments (9)
  • Popular
  • New
  • Old
You must be signed in to leave a comment
Karas Java Developer
7 September 2020, 23:05
Check this out: https://docs.oracle.com/javase/tutorial/essential/concurrency/sleep.html
David Haines
Level 13 , La Crosse, United States
22 July 2020, 20:17
I found this and it compiled and verified successfully: public static void main(String[] args) throws Throwable
Edddieg
Level 15 , Providence, United States
25 June 2020, 02:00
this code is scary
Peter Karanyi
Level 9 , Cowplain, United Kingdom
12 June 2020, 10:56
You have to add "throws InterruptedException" otherwise it won't compile!
Janusz
Level 11 , Radomsko, Poland
5 January 2019, 14:25
com/codegym/task/task07/task0723/Solution.java:15: error: unreported exception java.lang.InterruptedException; must be caught or declared to be thrown Thread.sleep(100); ^ com/codegym/task/task07/task0723/Solution.java:17: error: unreported exception java.lang.InterruptedException; must be caught or declared to be thrown Thread.sleep(100); ^ What is wrong public class Solution { public static void main(String[] args) throws IOException { for (int i = 30; i >= 0; i--) { System.out.println(i); Thread.sleep(100); } Thread.sleep(100); System.out.println("Boom!"); } }
Roman
Level 41
8 January 2019, 06:33
If you need help, something isn't right in your code, the server won't accept your solution (even if you are 100% sure that it is correct). Describe your question/issue in the HELP section at codegym.cc/help.
horst
Level 26 , Not in list
8 January 2020, 00:30
I am not an expert on exceptions, but I think your main method should throw an Interrupted Exception instead of an IO:
public static void main(String[] args) throws InterruptedException
By the way, could the CodeGym-team please fix this? I think exceptions are explained later than this task.
Arko Sarkar
Level 8 , Mumbai, India
1 September 2018, 05:48
What is Thread.sleep(100) and how does it advance the countdown ten times per second?
Roman
Level 41
3 September 2018, 05:48
Thread.sleep(100) allows to make pause in 1/10 second.