In this section we learn how we can make a program so that there are delay between the execution of program.
In this example we are using a sleep() method. We are passing 4000 to give the waiting time to our thread. This mean at execution time our program will wait for 4000 millisecond. The sleep() method can throws an InterruptedException .Show we must have write the sleep() method within try/catch block.
The code of the program is given below:
public class DelayExample{
|
The output of the program is given below:
C:\convert\rajesh\completed>javac DelayExample.java C:\convert\rajesh\completed>java DelayExample Hi Number of itartion = 0 Wait: Number of itartion = 1 Wait: Number of itartion = 2 Wait: Number of itartion = 3 Wait: Number of itartion = 4 Wait: Number of itartion = 5 Wait: Number of itartion = 6 Wait: Number of itartion = 7 Wait: Number of itartion = 8 Wait: Number of itartion = 9 -Wait: |
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.
Ask Questions? Discuss: Delay Example View All Comments
Post your Comment