public class TestNumber {
public static void main(String[] args) {
Object o = new Object();
Thread t1 = new Thread(new ThreadA(o));
t1.start();
Thread t2 = new Thread(new ThreadB(o));
t2.start();
}
}
class ThreadA implements Runnable { private Object o; public ThreadA(Object o) { this.o = o; } public void run() { synchronized (o) { for (int i = 0; i < 26; i++) { System.out.print(i + 1); o.notifyAll(); try { if (i != 25) { o.wait(); } } catch (Exception e) { e.printStackTrace(); } } } } }class ThreadB implements Runnable { private Object o; public ThreadB(Object o) { this.o = o; } public void run() { synchronized (o) { for (char c = 'A'; c <= 'Z'; c++) { System.out.println(c); o.notifyAll(); try { if (c != 'Z') { o.wait(); } } catch (InterruptedException e) { e.printStackTrace(); } } } } }