Skip to content
← Back to Community
Slow Print tutorial for JAVA!!!
Profile icon
plscodeinjava

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!

Voters
Profile icon
westrajos
Profile icon
EshaanAhuja
Profile icon
IGamer123
Profile icon
joe201610a
Profile icon
DungeonMaster00
Profile icon
plscodeinjava
Comments
hotnewtop
Profile icon
IGamer123

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

Profile icon
DungeonMaster00

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

Profile icon
plscodeinjava

@nk1rwc
Dude thanks!

Profile icon
codingjlu

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

Profile icon
plscodeinjava

@codingjlu
how did you find this lol

Profile icon
codingjlu

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

Profile icon
plscodeinjava