very easy volatile solution with synchronized
\nclass ZeroEvenOdd {\n    private int n;\n    volatile boolean oddOrNot = true;\n    volatile boolean zeroOrNot = true;\n    \n    public ZeroEvenOdd(int n) {\
```\nclass ZeroEvenOdd {\n    private int n;\n    volatile boolean oddOrNot = true;\n    volatile boolean zeroOrNot = true;\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 synchronized void zero(IntConsumer printNumber) throws InterruptedException {\n        for (int i = 0; i < n; i++) {\n            while (!zeroOrNot) {\n                wait();\n            }\n            printNumber.accept(0);\n            zeroOrNot = false;\n            notifyAll();\n        }\n    }\n\n    public synchronized void even(IntConsumer printNumber) throws InterruptedException {\n        for (int i = 2; i <= n; i += 2) {\n            while (zeroOrNot) {\n                wait();\n            }\n            while (zeroOrNot || oddOrNot) {\n                wait();\n            }\n            printNumber.accept(i);\n            oddOrNot = true;\n            zeroOrNot = true;\n            notifyAll();\n        }\n    }\n\n    public synchronized void odd(IntConsumer printNumber) throws InterruptedException {\n        for (int i = 1; i <= n; i += 2) {\n            while (zeroOrNot) {\n                wait();\n            }\n            while (zeroOrNot || !oddOrNot) {\n                wait();\n            }\n            printNumber.accept(i);\n            oddOrNot = false;\n            zeroOrNot = true;\n            notifyAll();\n        }\n    }\n}\n```
[]