【16】一个计数器计数到100,在每个数字之间暂停1秒,每隔10个数字输出一个字符串。
public class MyThread extends Thread{
public void run()
{
for(int i=0;i<100;i++)
{
if(i%10==0)
{
System.out.println("------"+i);
}
System.out.print(i);
try {
Thread.sleep(1);
System.out.print(" 线程睡眠1毫秒!\n");
}catch(InterruptedException e){
e.printStackTrace();
}
}
}
public static void main(String[] args) {
new MyThread().start();
}
}