7 Answers
New Answerabdul rahman It is cause method sleep can potentially throw an exception in this case you can wrap your code in try/catch public class Program { public static void main(String[] args) { try {System.out.println("before sleep"); Thread.sleep(1000); System.out.println("after sleep"); } catch (Exception e){ System.out.println("Exception");} } }
You could simply use Thread.sleep(1000) where the argument's in milliseconds. So 1000 means 1 seconds. Or - for a non-blocking approach - the Timer class: https://docs.oracle.com/javase/10/docs/api/java/util/Timer.html
SoloLearn Inc.
4 Embarcadero Center, Suite 1455Send us a message