public class Main {

    public static void main(String[] args) {
        for (int i = 0; i < 3; i++) {
            new Thread(new Printer(i), String.valueOf((char) (i + 'A'))).start();
        }
    }

    static class Printer implements Runnable {
        private int id;
        static int count;

        public Printer(int id) {
            this.id = id;
        }

        @Override
        public void run() {
            for (int i = 0; i < 10; i++) {
                synchronized (Printer.class) {
                    while (count % 3 != id) {
                        try {
                            Printer.class.wait();
                        } catch (InterruptedException e) {
                            e.printStackTrace();
                        }
                    }
                    System.out.println(Thread.currentThread().getName());
                    Printer.count++;
                    Printer.class.notifyAll();
                }
            }
        }
    }
}