创建两个线程,每个线程打印出线程名字后再睡眠,给其它线程以执行的机会,主线程也要打印出线程名字后再睡眠,每个线程前后共睡眠5次。要求分别采用从Thread中继承和实现Runnable接口两种方式来实现程序。(即写两个程序)第一种方式:  
/**Creat two threads that write their names and sleep. The main thread also
* writes its name and sleeps.
*/
import java.io.*;
public class NameThread extends Thread
{
int time;//time in milliseconds to sleep
public NameThread(String n,int t){
super(n);
time = t;
}
public void run(){
for(int i=1;i<=5;i++){
System.out.println(getName()+""+i);
try{
Thread.sleep(time);
}catch(InterruptedException e){ return; }
}
}
public static void main(String args[]){
NameThread bonnie = new NameThread("Bonnie",1000);
bonnie.start();
NameThread clyde = new NameThread("Clyde",700);
clyde.start();
for(int i=1;i<=5;i++){
          System.out.println(Thread.currentThread().getName()+""+i);
  try{
  Thread.sleep(1000);
  }catch(InterruptedException e){ return; }
}
}
}