Delayed Output in Java
Due to the code containing a lot of intricate content. The contains two static methods that can be implemented into programs to help delay string outputs.
Adding a Simple Delay
/**
* This method adds a milliseconds delay to your code.
* @param ms is an integer value representing milliseconds
*/
public static void delay(int ms) {
try {
Thread.sleep(ms);
} catch (InterruptedException e) {
// Handle the exception if needed
e.printStackTrace();
}
}This method can be called upon to add a delay. 1000 ms will be a 1 second delay.
Two Methods
Method 1: delayedMessage()
delayedMessage()The delayedMessage() method will output the given message to the console then apply a delay (measured in milliseconds) afterwords. Therefore, any lines of code that happen directly after will be delayed by a given ms parameter.
Method 2: typeIt()
typeIt()The typeIt() method will simulate a person typing out each individual character in a string. The speed of the typing can be set as the second parameter measured in milliseconds.
Last updated