How to pause execution for 5 seconds in Java

1 Answer

0 votes
public class PauseExecution {
    public static void main(String[] args) {
        System.out.println("Pause for 5 seconds...");
        
        try {
            // Pause execution for 5000 milliseconds (5 seconds)
            Thread.sleep(5000);
        } catch (InterruptedException e) {
            // Handle the exception if the thread is interrupted
            e.printStackTrace();
        }
        
        System.out.println("Execution resumes.");
    }
}



/*
run:

Pause for 5 seconds...
Execution resumes.

*/

 



answered Apr 30, 2025 by avibootz

Related questions

1 answer 176 views
2 answers 197 views
1 answer 169 views
1 answer 187 views
1 answer 144 views
144 views asked Apr 30, 2025 by avibootz
1 answer 170 views
2 answers 169 views
...