The following Java code pause the threads.
import java.util.Scanner;
public class PauseThreads
{
public static void main(String[] args)
{
//* * Please note that, this method may throw InterruptedException.
System.out.print("Enter how many numbers you want: ");
Scanner input = new Scanner(System. in );
int num = input.nextInt();
System.out.println("Print numbers after pausing for 500 milliseconds");
try
{
for (int i = 0; i < num; i++)
{
System.out.println(i);
/*
* This thread will pause for 500 milliseconds after
* printing each number.
*/
Thread.sleep(500);
}
}
catch (InterruptedException ie)
{
System.out.println("Thread interrupted !" + ie);
}
}
}Thank you, keep learning and sharing
