黑马程序员技术交流社区
标题:
多线程打印1到100
[打印本页]
作者:
_Water
时间:
2014-5-10 08:53
标题:
多线程打印1到100
本帖最后由 _Water 于 2014-7-22 17:12 编辑
public class Test2 {
static class MyThread implements Runnable {
int i;
int MaxLimit;
MyThread(int pI,int pMaxLimit){
this.i=pI;
this.MaxLimit=pMaxLimit;
}
@Override
public void run() {
print();
}
void print() {
try {
System.out.println(i * ((MaxLimit + 1 - i) / (MaxLimit + 1 - i)));
new Thread(new Test2.MyThread(this.i+1,this.MaxLimit)).start();
} catch (Exception e) {
}
}
}
public static void main(String[] args) {
new Thread(new Test2.MyThread(1,100)).start();
}
}
复制代码
作者:
郑云斌
时间:
2014-5-10 09:07
不错,一个简单的程序,运用到了很多个知识点,赞一个。
欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/)
黑马程序员IT技术论坛 X3.2