Java solution Semaphore
```\nclass ZeroEvenOdd {\n    private int n;\n    private int k = 1;\n    private Semaphore semOdd = new Semaphore(0);\n    private Semaphore semEven = new Sema
```\nclass ZeroEvenOdd {\n    private int n;\n    private int k = 1;\n    private Semaphore semOdd = new Semaphore(0);\n    private Semaphore semEven = new Semaphore(0);\n    private Semaphore semZero = new Semaphore(1);\n    \n    public ZeroEvenOdd(int n) {\n        this.n = n;\n    }\n\n    // printNumber.accept(x) outputs "x", where x is an integer.\n    public void zero(IntConsumer printNumber) throws InterruptedException {\n        for (int i = 0; i < n; ++i) {\n            semZero.acquire();\n            printNumber.accept(0);\n            if (k % 2 == 0) {\n                semEven.release();\n            }\n            else {\n                semOdd.release();\n            }\n        }\n    }\n\n    public void even(IntConsumer printNumber) throws InterruptedException {\n        for (int i = 2; i <= n; i += 2) {\n            semEven.acquire();\n            printNumber.accept(i);\n            k++;\n            semZero.release();\n        }\n    }\n\n    public void odd(IntConsumer printNumber) throws InterruptedException {\n        for (int i = 1; i <= n; i += 2) {\n            semOdd.acquire();\n            printNumber.accept(i);\n            k++;\n            semZero.release();\n        }\n    }\n}
[]