i-am-zach/DHS-Computer-Science

how do I use Thread.sleep????????

Closed this issue · 2 comments

how do I use Thread.sleep????????
  1. Wrap your program in a "try-catch"
public class MyProgram extends ConsoleProgram {
    public void run() {
         try {
             // Your code goes here
         }  catch(Exception e) {
             // Leave this empty
         }
    }
}
  1. Use Thread.sleep to pause the program
public class MyProgram extends ConsoleProgram {
    public void run() {
         try {
             System.out.println("Please wait one second");
             Thread.sleep(1000); // 1000 -> 1000 miliseconds or one second
             System.out.println("Thank you!");
         }  catch(Exception e) {
             // Leave this empty
         }
    }
}

Do not worry about understanding what a "try-catch" is yet. You will learn about it in a later unit!