making text appear delayed

前端 未结 4 1970
故里飘歌
故里飘歌 2021-01-22 08:19

I want to make text appear in the following way:

H
wait 0.1 seconds
He
wait 0.1 seconds
Hel
wait 0.1 seconds
Hell
wait 0.1 seconds
Hello

But I\

4条回答
  •  孤独总比滥情好
    2021-01-22 09:23

    String text = "Hello";
    
    for(int i=1; i<=text.length();i++){
       System.out.println(text.substring(0, i));
        try {
           Thread.sleep(100); 
        } catch (Exception e) {
           e.printStackTrace();
        }
    }
    

    Edit: if you want only 1 character by 1, than:

    for(int i=0; i

提交回复
热议问题