ADVERTISEMENT
ADVERTISEMENT

Java program to sleep program execution for specified milliseconds

Write a Java program to sleep program execution for specified milliseconds.
Submitted by Nidhi, on March 04, 2022

Problem Solution:

In this program, we will sleep program execution 4 specified milliseconds using Thread.Sleep() method.

Program/Source Code:

The source code to sleep program execution for specified milliseconds is given below. The given program is compiled and executed successfully.

// Java program to sleep program 
// for specified milliseconds

public class Main {
  public static void main(String[] args) {
    try {
      System.out.println("Hello");
      Thread.sleep(1000);
      System.out.println("Hii");
    } catch (Exception e) {
      System.out.println(e);
    }
  }
}

Output:

Hello
Hii

Explanation:

In the above program, we created a public class Main. It contains a static method main().

The main() method is an entry point for the program. Here, we printed the "Hello" message. Then we slept program execution for 1000 milliseconds. After that, we printed the "Hii" message.

Java Basic Programs »


ADVERTISEMENT
ADVERTISEMENT


Comments and Discussions!



ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.