HOW I DO A DELAY IN JAVA ??? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

HOW I DO A DELAY IN JAVA ???

i want to put a delay on a program in java but i dont know. plz help https://code.sololearn.com/c8VwBerV2nsn/?ref=app

14th May 2018, 3:20 AM
Alexandre Filho
Alexandre Filho - avatar
2 Answers
+ 5
public static void main(String[ ] args) throws InterruptedException For more info: https://docs.oracle.com/javase/7/docs/api/java/lang/InterruptedException.html Unfortunately, it doesn't work as expected in the SoloLearn Code Playground. This is the working code in action: https://code.sololearn.com/c3FbfOsUDviJ/?ref=app
14th May 2018, 3:27 AM
Dev
Dev - avatar
+ 4
And you can use Thread.Sleep(5000); public static void main(String... a) { --- here your code you want to run before ----- try{ Thread.Sleep(5000);} catch (Exception e) {} --- here that code you want to run after 5 sec --- -- } } this might help you
14th May 2018, 5:36 AM
Arun Tomar
Arun Tomar - avatar