class Cannons {  //
private boolean shells=false;
private int i,j=0;
synchronized void shot(){  //ڵ
		while(!shells){
			try{wait();	}
			catch(InterruptedException e){
				System.out.print("ж");}
}
		shells=false;
		i++;
		if(i>5)     //5κ˳
		{	System.exit(1);}
		System.out.println("ڵ"+i+"ηϣװڵ");
		notify();  //װ
	}
	synchronized void load(){
		while(shells){
			try{ wait();}
			catch(InterruptedException e){
				System.out.print("ж");}
}
		shells=true;
		j++;
		if(j>5)
		{	System.exit(1);}
		System.out.println("ڵװ");
		notify();    //֪ͨ
	}
}
class Artillery extends Thread{   //
	Cannons cannon;
	Artillery(Cannons cannon){
		this.cannon=cannon;}
	public void run(){
		while(true){
			cannon.shot();}
	}
}
class Filler extends Thread{     //װ
	Cannons cannon;
	Filler(Cannons cannon){
		this.cannon=cannon;}
	public void run(){
		while(true){
			cannon.load();}
	}
}
public class Fight {           //ս
public static void main(String args[]){
		Cannons cannon=new Cannons();
		new Filler(cannon).start();  //װ߳
		new Artillery(cannon).start();  //߳
	}
}
