How to do delay in java | SoloLearn: Learn to code for FREE!


How to do delay in java

5/2/2019 5:42:59 AM

@bdul rahman;

7 Answers

New Answer


abdul 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:


Thread.sleep(1000) With argument number of milliseconds


I see an error when I write this


Thread.sleep(t) as mentioned before should work fine in a try-catch block


I did create a delay in c but it was for the detpic32.


Used sleep method