Clocks

  • 4
  • Locked
Classic Terrian clocks say "tick-tock". And they should sound the same in our program. Figure out what the program does and implement the printTickTock method. In the first half of each second, the method should display "Tick." In the second half of each second, it should display "Tock."
You can't complete this task, because you're not signed in.
Comments (2)
  • Popular
  • New
  • Old
You must be signed in to leave a comment
LuisRC
Level 39 , Gijón, Spain
22 February 2022, 16:59
Are the conditions on this task well explained? I mean: 2.1. In the first half of each second, the following phrase should be displayed: Tick 2.2. In the second half of each second, the following phrase should be displayed: Tock To my undesrtanding and according to the solution given by CODEGYM:
private void printTickTock() throws InterruptedException {
            // add your code here
            Thread.sleep(500);
            System.out.println("Tick");
            Thread.sleep(500);
            System.out.println("Tock");
        }
The first Thread.sleep(500) stops the Thread for 500ms (1/2s) and then it prints out "Tick" but this printing is made in the second half of the second. Pretty the same for the Tock printing which would be made in the first half of the second second. I hope I were able to explain myself.
Nikita Petrov Controls engineer
30 May 2022, 05:30
I guess it should be "Tick"/"Tock" first and sleep() second.