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);
Countdown
- 2
Locked
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
0
David Haines
22 July 2020, 20:17
I found this and it compiled and verified successfully:
public static void main(String[] args) throws Throwable
+2
Edddieg
25 June 2020, 02:00
this code is scary
0
Peter Karanyi
12 June 2020, 10:56
You have to add "throws InterruptedException" otherwise it won't compile!
+1
Janusz
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!");
}
}
0
Roman
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.
0
horst
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:
By the way, could the CodeGym-team please fix this? I think exceptions are explained later than this task. +2
Arko Sarkar
1 September 2018, 05:48
What is Thread.sleep(100) and how does it advance the countdown ten times per second?
0
Roman
3 September 2018, 05:48
Thread.sleep(100) allows to make pause in 1/10 second.
+2