class WoTou{
int id;
WoTou(int id ){
this.id=id;
}
public String toString(){
return "id="+id;
}

}
class LanZi{
int idex=0;
WoTou arridex[]=new WoTou[6];public synchronized void push(WoTou wt){
if(idex==arridex.length){
try{
this.wait();
}
catch(Exception e){

e.printStackTrace();
}
}
this.notify();
arridex[idex]=wt;
idex++;
}public synchronized WoTou pop(){
if(idex==0){
try{
this.wait();
}
catch(Exception e){

e.printStackTrace();
}
}
this.notify();
idex--;
 return arridex[idex];
}
}
 class por implements Runnable{                 //生产者
 LanZi lz=null;
 por(LanZi lz){
 this.lz=lz;
 }
 public void run(){
 for(int i=0;i<20;i++){
 WoTou wt=new WoTou(i);
 lz.push(wt);
 }
 
 try{
 Thread.sleep(1000);
 }
 catch(Exception e){
 e.printStackTrace();
 }
 }
 }
class cust implements Runnable{                     //消费者
LanZi lz=null;
cust(LanZi lz){
this.lz=lz;
}
public void run(){
for(int i=0;i<20;i++){
 WoTou wt=lz.pop();
System.out.println(wt);
}
} public class Demo{
public static void main(String[] args){ LanZi lz =new LanZi();
por p=new por(lz);
cust c=new cust(lz);
Thread th=new Thread(p).start();
Thread th1=new Thread(c).start(); }
}

解决方案 »

  1.   

     catch(Exception e){ e.printStackTrace(); 

    }
    多个花括号
      

  2.   

    终于找到了class cust implements Runnable{                    //消费者 
    LanZi lz=null; 
    cust(LanZi lz){ 
    this.lz=lz; 

    public void run(){ 
    for(int i=0;i <20;i++){ 
    WoTou wt=lz.pop(); 
    System.out.println(wt); 


    这个类少个“}”
      

  3.   

    谢谢了,按你说的问题解决了!!但又出事了:
    public class Demo{
    public static void main(String[] args){                                                             
    LanZi lz =new LanZi();
    por p=new por(lz);
    cust c=new cust(lz);
    Thread th=new Thread(p).start();            //这里又说:类型不匹配:不能从 void 转换为 Thread
    Thread th1=new Thread(c).start();          //这里又说:类型不匹配:不能从 void 转换为 Thread }
    }   
    怎么办啊??又是那里出问题了?????
      

  4.   

    谢谢了,按你说的问题解决了!!但又出事了: 
    public class Demo{ 
    public static void main(String[] args){                                                            
    LanZi lz =new LanZi(); 
    por p=new por(lz); 
    cust c=new cust(lz); 
    Thread th=new Thread(p).start();            //这里又说:类型不匹配:不能从 void 转换为 Thread 
    Thread th1=new Thread(c).start();          //这里又说:类型不匹配:不能从 void 转换为 Thread } 
    }  
    怎么办啊??又是那里出问题了?????
      

  5.   


    Thread th=new Thread(p).start();         
    Thread th1=new Thread(c).start();改成Thread th = new Thread(p);
    Thread th1 = new Thread(c);
    th.start();
    th1.start();