Delayed Printing Using Threads In Java
The bellow code snippet will perform the printing of the numbers in the loop till with a time gap of 1sec. You can modify the bellow snippet and add your creativity to try something new. Basically Thread.sleep() makes the thread to wait for the specified time !
Screenshots[Demo]:
The Code:
Got Bugs, Drop them here ! And yes don't forget to subscribe us ! ;)
Screenshots[Demo]:
The Code:
class DelayPrint { public static void main(String args[]) { try { for(int n = 5; n > 0; n--) { System.out.println(n); Thread.sleep(1000);// Time Gap of 1 sec } } catch (InterruptedException e) { System.out.println("Main thread interrupted"); } } }
Got Bugs, Drop them here ! And yes don't forget to subscribe us ! ;)
Comments
Post a Comment