题目一:写两个线程,一个线程打印1~52,另一个线程打印字母A~Z。打印顺序为12A34B56C........5152Z。要求用线程间的通信。package test;
import java.lang.Thread;
class Printer{
private int index = 1;
public synchronized void print(int n){
while(index%3==0){
try{
wait();
/*在其他线程调用此对象的notify方法钱,导致当前线程等待*/
}catch(Exception e)
{
e.printStackTrace();
}
}
System.out.print(index);
index++;
notifyAll();
}
public synchronized void print(char c){
while(index%3!=0){
try{
wait();
}catch(Exception e){
e.printStackTrace();
}
}
System.out.print(c);
System.out.print(index);
index++;
notifyAll();
}
}
class