/*
一个逐字显示句子的程序
*/
package com.main;
import java.util.Scanner;
public class Text {
public static Scanner sout = new Scanner(System.in);
public static void main(String[] args) {
MyThread my = new MyThread();
Thread th = new Thread(my);
System.out.print("请输入你要显示的句子 '#'键结束:");
th.start();
}
}
class MyThread implements Runnable {
public void run() {
String len;
while (!(len = Text.sout.nextLine()).equals("#")) {
for (int i = 0; i < len.length(); i++) {
try {
Thread.sleep(500);
} catch (Exception e) {
System.out.println(e);
}
if (i % 10 == 0 && i != 0)
System.out.println();
System.out.print(len.charAt(i));
}
System.out.print("\n请输入你要显示的句子 '#'键结束:");
}
}
}
多线程复习
最新推荐文章于 2022-11-09 09:14:37 发布