Question about wait and timers.... | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Question about wait and timers....

I want to know what library and syntax about delaying code, timing it and such. Ty!

3rd Jan 2021, 2:57 PM
AtharvATAR
AtharvATAR - avatar
2 Answers
+ 1
Java has a Thread class for that you can use Thread.sleep(10); to wait 10 milliseconds. But it could throws a InterruptedException. So you should surround your the sleep method with a try and catch like shown below. https://www.sololearn.com/learn/Java/2177/?ref=app https://www.sololearn.com/learn/Java/2185/?ref=app
4th Jan 2021, 5:32 PM
Stefanoo
Stefanoo - avatar
+ 1
Java also have a Clock class. Here is an example I wrote. https://code.sololearn.com/ca3GSqMQb1PO/?ref=app
4th Jan 2021, 5:57 PM
Stefanoo
Stefanoo - avatar