黑马程序员技术交流社区

标题: 多线程打印1到100 [打印本页]

作者: _Water    时间: 2014-5-10 08:53
标题: 多线程打印1到100
本帖最后由 _Water 于 2014-7-22 17:12 编辑
  1. public class Test2 {

  2.      static class MyThread implements Runnable {
  3.                int i;
  4.                int MaxLimit;
  5.         MyThread(int pI,int pMaxLimit){
  6.             this.i=pI;
  7.             this.MaxLimit=pMaxLimit;
  8.         }
  9.         @Override
  10.         public void run() {
  11.             print();
  12.         }

  13.         void print() {
  14.             try {
  15.                 System.out.println(i * ((MaxLimit + 1 - i) / (MaxLimit + 1 - i)));
  16.                 new Thread(new Test2.MyThread(this.i+1,this.MaxLimit)).start();
  17.             } catch (Exception e) {
  18.             }
  19.         }
  20.     }

  21.     public static void main(String[] args) {

  22.         new Thread(new Test2.MyThread(1,100)).start();
  23.     }
  24. }
复制代码

作者: 郑云斌    时间: 2014-5-10 09:07
不错,一个简单的程序,运用到了很多个知识点,赞一个。




欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/) 黑马程序员IT技术论坛 X3.2