Skip to content
Sign upLog in
This post is read-only. Explore Repls and connect with other creators on Community.View Community
The info in this post might be out of date, check out our docs instead. View docs
2

How can I make letter by letter output show in Java?

ZacPlayz
ZacPlayz

I want to make letter by letter output in my game "The War" to make it more nice and fancy, since I am considered a "beginner" in my coding lessons, but I do some self-taught, and so that's why I'm asking... :P so that I can gain some self-taught knowledge for my game. Please write in the comments what commands I should use, and please write the commands with the System.out.println(""); so that I can learn to use the command. Whoever answered me first and likes this post will get 5 cycles for the answer and a like on the comment itself, overall 6 cycles!! So be quick!! :P

3 years ago

Voters

Comments

TopNew
3
SixBeeps
SixBeeps

Ah yes, rolling text. Here's a method for ya:

public static void RollText(String msg) { for(int i = 0; i < msg.length(); i++) { System.out.print(msg.charAt(i)); Thread.sleep(100); } }
3 years ago
0
ZacPlayz
ZacPlayz

Thanks!! You have earned 6 cycles

@SixBeeps
Congratulations!!

3 years ago
0
ZacPlayz
ZacPlayz

wait wait wait look at this

@SixBeeps
!!

public class Main {
public static void main(String[] args) {

public static void RollText(String msg) {
for(int i = 0; i < msg.length(); i++) {
System.out.print(msg.charAt(i));
Thread.sleep(100);
System.out.println("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@");
}
}

}
}

3 years ago
0
ZacPlayz
ZacPlayz

The ats (@) are just for to make it more run-on I guess but this thing doesn't work!! Did I put it in the wrong combination??

3 years ago
3
SixBeeps
SixBeeps

@ZacPlayz
No, you're supposed to call my method instead of using System.out.println for putting things to the screen.
Use this instead:

import java.lang.*; public class Main { public static void main(String[] args) throws InterruptedException { RollText("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n"); } public static void RollText(String msg) throws InterruptedException { for(int i = 0; i < msg.length(); i++) { System.out.print(msg.charAt(i)); Thread.sleep(50); } } }
3 years ago
0
ZacPlayz
ZacPlayz

This is what pops up...

@SixBeeps

Main.java:8: error: unreported exception InterruptedException; must be caught or declared to be thrown
Thread.sleep(100);
^
1 error

3 years ago
0
ZacPlayz
ZacPlayz

btw u forgot to put another wavy bracket } at the end to mark the end of public class Main {

@SixBeeps

3 years ago
0
ZacPlayz
ZacPlayz

And when you put the last wavy bracket you get what I wrote that pops up

3 years ago
1
SixBeeps
SixBeeps

@ZacPlayz
Ah I forgot to end the for loop :P

3 years ago
2
SixBeeps
SixBeeps

@ZacPlayz
Ok I updated the code above. Imma test this out too because threading seems weird in Java.

EDIT: I just tested it and posted fixed code above.

3 years ago
1
ZacPlayz
ZacPlayz

nice!! works now thx!!!!

@SixBeeps

3 years ago
Load more