题目如下:
创建线程,输出数字1到100,在每个数字输出之间相隔1秒,用sleep()方法实现,并遵循如下要求:
1、用实现Runnable接口方式创建一个线程t。
2、重写run()方法,用于输出数字的代码位于其中。
3、每输出10个数字以后,输出一个字符串“已经完成10个数字。”
4、long型数字表示毫秒。我编写的代码如下:
public class TestThread{
public static void mian(String [] args){
Thread thread=new Thread(new Runnable(){
public void run() {
     for ( int i = 1; i <= 100; i++) {
if (i%10 == 0){
      System.out.println("已经完成10个数字!");
     }    
try{
       Thread.sleep(1000);  
System.out.println(i);
     }catch(InterruptedException e){ 
               System.out.println(" InterruptedException ");
             }
   }
}
});
thread.start();
}
}
请帮忙在我的基础上改动!!谢谢~~

解决方案 »

  1.   


    public class T {
    public static void main(String[] args) {
    Thread thread = new Thread(new Runnable() {
    public void run() {
    for (int i = 1; i <= 100; i++) {
    try {
    Thread.sleep(1000);
    System.out.println(i);
    if (i % 10 == 0) {
    System.out.println("已经完成10个数字!");
    }
    } catch (InterruptedException e) {
    System.out.println(" InterruptedException ");
    }
    }
    }
    });
    thread.start();
    }
    }
      

  2.   

    要改的……是华丽的函数名………………
    mian是啥东西来着………………
      

  3.   

    What goes around comes around...