用java编写一个程序 用于实现Runnable接口并创建两个线程

编写一个程序,用于实现Runnable接口并创建两个线程,分别输出从10~15的数,每个数字间延迟500毫秒,要求输出的结果如下所示:
10,11,12,13,14,15
10,11,12,13,14,15

第1个回答  推荐于2016-09-11
public class TestThreadOutput {

public static void main(String[] args) {
OutputInt opi=new OutputInt();
Thread th1=new Thread(opi);
Thread th2=new Thread(opi);
th1.start();
th2.start();
}
}
class OutputInt implements Runnable{

public void run() {
for(int i=10;i<=15;i++){
System.out.print(i+",");
try {
Thread.sleep(500);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}

}本回答被提问者采纳
相似回答