如何让一段段话一个字一个字打印出来
这里主要用到的就是for循环嵌套和Thread.sleep()方法。
class MyThread2 implements Runnable{
String s[] = {"村里有个姑娘叫小芳","长得好看又善良","一双美丽的大眼睛","辫子粗又长"};
@Override
public void run() {
// TODO Auto-generated method stub
for(int i=0;i<s.length;i++) {
for(int j=0;j<s[i].length();j++) {
char[] chars = s[i].toCharArray();
try {
Thread.sleep(100);
System.out.print(chars[j]);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
System.out.println();
}
}
}
然后就是再main方法里面new起来
public class test1114 {
public static void main(String[] args) {
// TODO Auto-generated method stub
MyThread2 m = new MyThread2();
m.run();
}
}