How to pause execution for 5 seconds in Kotlin

2 Answers

0 votes
fun main() {
    println("Pausing for 5 seconds...")
    
    Thread.sleep(5000) // Pause execution for 5000 milliseconds (5 seconds)
    
    println("Resuming execution.")
}

   
      
/*
run:

Pausing for 5 seconds...
Resuming execution.
  
*/

 



answered Apr 30, 2025 by avibootz
0 votes
import kotlinx.coroutines.runBlocking
import kotlinx.coroutines.delay

fun main() = runBlocking {
    println("Pausing for 5 seconds...")
    
    delay(5000) // Suspend for 5000 milliseconds (5 seconds)
    
    println("Resuming execution.")
}

   
      
/*
run:

Pausing for 5 seconds...
Resuming execution.
  
*/

 



answered Apr 30, 2025 by avibootz

Related questions

1 answer 148 views
2 answers 166 views
1 answer 139 views
1 answer 162 views
1 answer 117 views
117 views asked Apr 30, 2025 by avibootz
1 answer 138 views
1 answer 125 views
...