Java 3 Semaphore solution
\n\nclass ZeroEvenOdd {\n    private int n;\n    private int m;\n    private Semaphore semaphoreEven, semaphoreOdd, semaphoreZero;\n    \n    public ZeroEvenOdd
```\n\nclass ZeroEvenOdd {\n    private int n;\n    private int m;\n    private Semaphore semaphoreEven, semaphoreOdd, semaphoreZero;\n    \n    public ZeroEvenOdd(int n) {\n        this.n = n;\n        m = 0;\n        semaphoreZero = new Semaphore(1);\n        semaphoreEven = new Semaphore(0);\n        semaphoreOdd = new Semaphore(0);\n    }\n\n    // printNumber.accept(x) outputs "x", where x is an integer.\n    public void zero(IntConsumer printNumber) throws InterruptedException {\n        while (m <= n) {\n            semaphoreZero.acquire();\n            if (++m > n) break;\n            printNumber.accept(0);\n            if (m % 2 == 1) \n                semaphoreOdd.release();\n            else\n                semaphoreEven.release();\n        }\n        semaphoreOdd.release();\n        semaphoreEven.release();\n    }\n\n    public void even(IntConsumer printNumber) throws InterruptedException {\n        while (m <= n) {\n            semaphoreEven.acquire();\n            if (m > n) break;\n            printNumber.accept(m);\n            semaphoreZero.release();\n        }\n    }\n\n    public void odd(IntConsumer printNumber) throws InterruptedException {\n        while (m <= n) {\n            semaphoreOdd.acquire();\n            if (m > n) break;\n            printNumber.accept(m);\n            semaphoreZero.release();\n        }\n    } \n}\n```
[]