Java Condition solution
\nimport java.util.concurrent.locks.Condition;\nimport java.util.concurrent.locks.Lock;\nimport java.util.concurrent.locks.ReentrantLock;\nimport java.util.func
```\nimport java.util.concurrent.locks.Condition;\nimport java.util.concurrent.locks.Lock;\nimport java.util.concurrent.locks.ReentrantLock;\nimport java.util.function.IntConsumer;\n\nclass ZeroEvenOdd {\n    private int n;\n    private Lock lock = new ReentrantLock();\n    private Condition zeroCondition = lock.newCondition();\n    private Condition evenCondition = lock.newCondition();\n    private Condition oddCondition = lock.newCondition();\n    private volatile boolean beginZero = true;\n    private volatile boolean beginEven = false;\n    private volatile boolean beginOdd = false;\n    private int i = 1;\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        lock.lock();\n        while (i <= n) {\n            while (!beginZero) zeroCondition.await();\n            if (i > n) break;\n            printNumber.accept(0);\n            beginZero = false;\n            if ((i & 1) == 1) {\n                beginOdd = true;\n                oddCondition.signal();\n            } else {\n                beginEven = true;\n                evenCondition.signal();\n            }\n        }\n        beginOdd = true;\n        oddCondition.signal();\n        beginEven = true;\n        evenCondition.signal();\n        lock.unlock();\n    }\n\n    public void even(IntConsumer printNumber) throws InterruptedException {\n        lock.lock();\n        while (i <= n) {\n            while (!beginEven) evenCondition.await();\n            if (i > n) break;\n            printNumber.accept(i++);\n            beginEven = false;\n            beginZero = true;\n            zeroCondition.signal();\n        }\n        lock.unlock();\n    }\n\n    public void odd(IntConsumer printNumber) throws InterruptedException {\n        lock.lock();\n        while (i <= n) {\n            while (!beginOdd) oddCondition.await();\n            if (i > n) break;\n            printNumber.accept(i++);\n            beginOdd = false;\n            beginZero = true;\n            zeroCondition.signal();\n        }\n        lock.unlock();\n    }\n}\n```
[]