Learn to Code via Tutorials on Repl.it!

← Back to all posts
Slow Print tutorial for JAVA!!!
amaddentcsec (239)

Hello! It's Amaddentcsec here with my FIRST tutorial. I decided to do something simple... Let's get right into it!

So first, we need a way to slow down the printing of the text. I use TimeUnit for this.
So, at the top of your code, write:
import java.util.concurrent.TimeUnit;
Now you're ready to write the slowPrint method.
Start with:
public static void slowPrint(String output) {
make sure you write void instead of something else. String output is the stuff we will be writing to the console. The next line will be making a for loop to iterate through String output.

public static void slowPrint(String output) {
    for (int i = 0; i<output.length(); i++) {

So now we have a variable i to iterate with. Continuing:

public static void slowPrint(String output) {
    for (int i = 0; i<output.length(); i++) {
      char c = output.charAt(i);
      System.out.print(c);

We get the character at index i of output, and then simply print it to the screen. This could be done in one line, but I'm trying to make this simple.
Lastly, we want to wait a bit until we print the next character.
We will use:
TimeUnit.MILLISECONDS.sleep(30);
You can use however many milliseconds you want to sleep for, but I like 30. We will need to wrap this in a try catch block.
The finished code looks like this:

public static void slowPrint(String output) {
    for (int i = 0; i<output.length(); i++) {
      char c = output.charAt(i);
      System.out.print(c);
      try {
        TimeUnit.MILLISECONDS.sleep(30);
      }
      catch (Exception e) {

      }
    }
}

To test this out, let's put:
slowPrint("Slowprinting");
In our main method. Once we run the program, we should see "Slowprinting" being slow printed to the console.
I hope you all liked this tutorial, and I hope you use it well!

PLEASE UPVOTE!

Thanks,
Amaddentcsec

Note: You can print in colors with this!

Comments
hotnewtop
IGamer123 (76)

Hey! Now I know how to slow print. Thanks @amaddentcsec

DungeonMaster00 (190)

This is a more in-depth version of a tutorial someone else made. Like it.

codingjlu (240)

@amaddentcsec Just use Thread.sleep()... no imports needed.

codingjlu (240)

@amaddentcsec lol I looked at tutorials with a Java tag xD