Java easy solution | 3 Semaphores
\nclass ZeroEvenOdd {\n    private int n;\n    private Semaphore zeroSem;\n    private Semaphore evenSem;\n    private Semaphore oddSem;\n    \n    \n    privat
```\nclass ZeroEvenOdd {\n    private int n;\n    private Semaphore zeroSem;\n    private Semaphore evenSem;\n    private Semaphore oddSem;\n    \n    \n    private boolean isOdd = true;\n    public ZeroEvenOdd(int n) {\n        this.n = n;\n        zeroSem = new Semaphore(1);\n        evenSem = new Semaphore(0);\n        oddSem = 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        for(int i=0; i<n; i++) {\n            zeroSem.acquire();\n            printNumber.accept(0);\n            System.out.print(0);\n            if(isOdd) \n                oddSem.release();\n            else \n                evenSem.release();\n        }       \n    }\n    \n    public void odd(IntConsumer printNumber) throws InterruptedException {\n        for(int i=1; i<=n; i+=2) {\n            oddSem.acquire();\n            printNumber.accept(i);\n            isOdd = false;\n            zeroSem.release();\n        }\n    }\n\n    public void even(IntConsumer printNumber) throws InterruptedException {\n        for(int i=2; i<=n; i+=2) {\n            evenSem.acquire();\n            printNumber.accept(i);\n            isOdd = true;\n            zeroSem.release();\n        }\n    }\n\n    \n}\n```
['Java']