[Java] 100% & 100% solution use synchronized lock simple to understand
\nclass ZeroEvenOdd {\n    private int n;\n    private boolean iszero=true;\n    private boolean isodd=true;\n    private boolean iseven=false;\n\n    private O
```\nclass ZeroEvenOdd {\n    private int n;\n    private boolean iszero=true;\n    private boolean isodd=true;\n    private boolean iseven=false;\n\n    private Object lock = new Object();\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        \n        for (int i = 0; i < n; i++) {\n           synchronized (lock) {\n            while(!iszero){\n                lock.wait();\n            }\n            printNumber.accept(0);\n            iszero=false;\n            lock.notifyAll();\n        }\n        }\n    }\n\n    public void even(IntConsumer printNumber) throws InterruptedException {\n        for (int i = 2; i <= n; i += 2) {\n        synchronized (lock) {\n            while(iszero || !iseven){\n                lock.wait();\n            }\n            printNumber.accept(i);\n            iseven=false;\n            isodd=true;\n            iszero=true;\n            lock.notifyAll();\n        }\n        }\n    }\n\n    public void odd(IntConsumer printNumber) throws InterruptedException {\n        for (int i = 1; i <= n; i += 2) {\n        synchronized (lock) {\n            while(iszero || !isodd){\n                lock.wait();\n            }\n            printNumber.accept(i);\n            iseven=true;\n            isodd=false;\n            iszero=true;\n            lock.notifyAll();\n        }\n        }\n    }\n}\n```
[]