I noticed a lot of the repls in repl.it are in python and a lot of the console programs are in python(because it is the most popular). A lot of them use slow print. So this tutorial teaches you how to slow print(print 1 char, wait, then write another char) in java.
My Code:
public class Main{
public static void main(String[] args){
slowPrint(50, "THIS WILL BE PRINTED CHAR BY CHAR");
}
public void slowPrint(int time, String toPrint){
char[] toPrintC = toPrint.toCharArray();// Create a char array and assign that to a string converted to a char array
for(int i = 0; i < toPrintC.length;i++){ // Create a for loop
System.out.print(toPrintC[i]);// Print the char
try{
Thread.sleep(time);// Stop printing for the amount of milliseconds specified(in the variable time)
}catch(Exception e){
e.printStckTrace();
}
// We surround in try/catch because Thread.sleep throws an exception
}
}
}
@Highwayman, yes, unfortunately it does. Good news is, I just finished the java OOP tutorial! I will post it now. (Remember how you asked why you should hide your data)
@Highwayman, Though about the Exception, you can dodge it by having EACH METHOD THAT USES ITthrows InterruptedException but then you would have to do that for EVERY METHOD THAT USES IT(As I just said) so I do not recommend doing that
I noticed a lot of the repls in repl.it are in python and a lot of the console programs are in python(because it is the most popular). A lot of them use slow print. So this tutorial teaches you how to slow print(print 1 char, wait, then write another char) in java.
My Code:
Hope this helps!
Does Thread.sleep always throw an exception?
@Highwayman, yes, unfortunately it does. Good news is, I just finished the java OOP tutorial! I will post it now. (Remember how you asked why you should hide your data)
@Highwayman, Here, https://repl.it/talk/learn/Java-OOP-Lesson-3-and-4/45034
@AbhayBhat hm strange...
Thanks! Yay! 😋
@Highwayman, Though about the Exception, you can dodge it by having EACH METHOD THAT USES IT
throws InterruptedException
but then you would have to do that for EVERY METHOD THAT USES IT(As I just said) so I do not recommend doing that@AbhayBhat hm ok, seems a bit like a hack anyways lol. Ty