class numThread extends Thread{
public numThread(){
// t.start();
}
Thread t=new Thread();
public void run(){
try{
for(int i=300;i>0;i--){
Thread.sleep(1000);
System.out.println(i);
while(i==0){
i=300;
}
}
}catch(Exception e){
System.out.println("Exception");
}
}
public static void main(String args[]){
new numThread().start;
}
}

解决方案 »

  1.   

    你得好好看看语法书了
    while(i==0){
    i=300;
    }
    这个怎么这样写呢?if( i == 0 ) 
        i = 300;
    不就行了吗?Java可不是英语啊
      

  2.   

    if( i == 0 ) 
        i = 300;
    ==================
    多此一举吧...class numThread extends Thread{
    Thread t=new Thread();
    public void run(){
    try{
    for(int i=300;i>0;i--){
    Thread.sleep(1000);
    System.out.println(i);
    }
    }catch(Exception e){
    System.out.println("Exception");
    }
    }
    public static void main(String args[]){
    numThread t=new numThread();
    t.start();
    }
    }
      

  3.   

    她不是想一直显示下去吗
    所以
    ==================
    if( i == 0 ) 
        i = 300;
      

  4.   

    你是我小女吗?class numThread extends Thread{
    public numThread(){
    t.start();
    }
    Thread t=new numThread ();//构造成你自己的类才能让它跑起来
    public void run(){
    try{
    for(int i=300;i>0;i--){
    Thread.sleep(1000);
    System.out.println(i);
    //while(i==0){
    // i=300;//你不是要循环,何必这样写呢
    //}
                                        if(i==0)
                                           i=300;
    }
    }catch(Exception e){
    System.out.println("Exception");
    }
    }
    public static void main(String args[]){
    new numThread();
    }
    }
      

  5.   

    package c;import EDU.oswego.cs.dl.util.concurrent.*;public class NumThread
      extends Thread {
        private static int n = 300;    private synchronized static int getAndSub() {
            if (n <= 0)
                return 0;
            return n--;
        }    public synchronized static int get() {
            return n;
        }    private Latch l;
        private CountDown c;
        public NumThread(Latch l, CountDown c) {
            if (l == null || c == null) {
                throw new NullPointerException();
            }        this.l = l;
            this.c = c;
        }    public void run() {
            try {
                try {
                    l.acquire();
                }
                catch (InterruptedException ie) {
                    ie.printStackTrace();
                    return;
                }            while (true) {
                    int n = getAndSub();
                    if (n <= 0)
                        break;                System.out.println(n);
                    try {
                        Thread.sleep( (int) (1000 * 0.1 * Math.random()));
                    }
                    catch (InterruptedException ie) {
                    }
                }
            }
            finally {
                this.c.release();
            }
        }    public static void main(String[] args) throws InterruptedException {
            int threadCount = 10;        Latch l = new Latch();
            CountDown c = new CountDown(threadCount);
            for (int i = 0; i < threadCount; i++) {
                new NumThread(l, c).start();
            }        System.out.println("starting...");
            l.release();        c.acquire();
            System.out.println("done.");
        }
    }
      

  6.   

    大概是这样吧:10,9,8,7,6,5,4,3,2,1,0,10,9......一直这样下去到断点为止:)
    class numThread extends Thread{
    Thread t=new Thread();
    public void run(){
    try{
    for(int i=10;i>=0;i--){
    Thread.sleep(1000);
    System.out.println(i);
    if(i==0){//这里可以用while;
    i=11;//这里改成11,因为有i--,否则就是9了;
    }
    }
    }catch(Exception e){
    System.out.println("Exception");
    }
    }
    public static void main(String args[]){
    numThread t=new numThread();
    t.start();
    }
    }
      

  7.   

    原来是要一直循环下去,楼上哥几个做的也太复杂了吧?这样不好吗:
    <<
    while(true) {
        for(int i=300;i>=0;i--) {
            // ....
        }
    }
    >>
      

  8.   


    //多线程输出300到0public class NumThread
    {
      int i=300;
      NumThread2 nt2;
      
      NumThread()
      {
       nt2= new NumThread2(NumThread.this);
       
       while(true)
       {
         try
          {Thread.sleep(500);
           System.out.println("Thread1 output : i="+i);
           if(i>0) i--; 
           else System.exit(0);
          }
        catch (InterruptedException e){}
       }
      }
      public static void main(String[] args)
      {
       NumThread nt=new NumThread();
      }
    }class NumThread2 extends Thread {
      NumThread nt1;
      
      public NumThread2(NumThread nt1) {
        this.nt1 = nt1;
        start();
      }
      public void run() {
        while(true)
        {
         try
          {Thread.sleep(500);
           System.out.println("Thread2 output : i="+nt1.i);
           if(nt1.i>0) nt1.i--; 
           else System.exit(0);
          }
         catch (InterruptedException e){} 
        }
      }   
    }