怎么写才是最好的结果呢

解决方案 »

  1.   

    LZ, 这个有意义么.? 一个for单线程不就ok了?
      

  2.   

    写两个多线程,一个输出奇数,一个输出偶数,再调用一下sleep()方法不就ok了。
    还有什么好的方法?期待高手解答……
      

  3.   

    public class ThreadTest implements Runnable { private static int tmep = 0; public void run() {
    int temp = this.returntemp();
    if (temp < 11) {
    System.out.println((temp + 1+" "));
    tmep++;
    }
    } private synchronized int returntemp() {
    return this.tmep;
    } public static void main(String[] args) {
    ThreadTest t1 = new ThreadTest();
    ThreadTest t2 = new ThreadTest();
    for (int i = 0; i < 5; i++) {
    t1.run();
    t2.run();
    }
    }
    }