[英]Java print character by character
So I have used a little function called typePhrase, and it allows me to give it any string, and it will print it in the console, letter by letter. 因此,我使用了一个名为typePhrase的小函数,它允许我给它提供任何字符串,并且它将在控制台中逐个字母地将其打印出来。
public static String typePhrase(String phrase) {
for(int i = 0; i < phrase.length(); i++) {
long start = System.currentTimeMillis();
while (System.currentTimeMillis() - start < 50) {
}
System.out.print(phrase.charAt(i));
}
return " ";
}
I am wondering if there is a way to make a function like this, but print lots of letters at once, for instance, every 50 milliseconds it would print out 7 letters all together. 我想知道是否有一种方法可以实现这样的功能,但是一次打印大量字母,例如,每隔50毫秒一次,它将总共打印7个字母。 The code that I am using now, prints one letter every 50 milliseconds.
我现在使用的代码每50毫秒打印一个字母。
Change 更改
for(int i = 0; i < phrase.length(); i++) {
to 至
for(int i = 0; i < phrase.length(); i += 7) {
and 和
phrase.charAt(i)
to 至
phrase.substring(i, Math.min(i + 7, phrase.length())
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.