0

How do you make a program that waits for 3 seconds? I've heard about this:

obj.wait()

But I'm just wondering about the syntax and what to import?

David Latimer
  • 65
  • 2
  • 9
  • `obj.wait()` is to wait until another thread calls `notify()`. Nothing directly to do with "waiting for X amount of time". – Steve Smith Aug 08 '18 at 15:57

2 Answers2

1

This will put your code to sleep for 3 seconds:

try{
Thread.sleep(3000);
} catch(InterruptedException e) {
 Thread.currentThread().interrupt();
}
light_303
  • 2,101
  • 2
  • 18
  • 35
1

You have to import `

java.util.concurrent.TimeUnit

`and the you can run:

TimeUnit.SECONDS.sleep(100);
Saboor
  • 352
  • 1
  • 10