There are times when we wish our Java code would run a lot slower e.g. when we want to count down from 10 to 0 with 1-second intervals. Here we can use “Thread.sleep(milliseconds)” see line 22 below.

Note that the sleep period is not precise as your computer is relying on an operating system that is time slicing to allow all processes to get CPU time.