Java Solution using Synchronized, wait and notifyAll
\nclass ZeroEvenOdd {\n    private int n;\n    private int count;\n    private int flag;\n    private boolean lastPrintedEven;\n    \n    public ZeroEvenOdd(int
```\nclass ZeroEvenOdd {\n    private int n;\n    private int count;\n    private int flag;\n    private boolean lastPrintedEven;\n    \n    public ZeroEvenOdd(int n) {\n        this.n = n;\n        this.count = 0;\n        \n        this.flag = 0;\n        lastPrintedEven = true;\n    }\n\n    // printNumber.accept(x) outputs "x", where x is an integer.\n    public synchronized void zero(IntConsumer printNumber) throws InterruptedException {\n        int numOfZeroes = n;\n        while(numOfZeroes-- > 0){\n        \twhile(flag != 0) {\n        \t\twait();\n        \t}\n            printNumber.accept(0);\n            if(lastPrintedEven)\n            flag = 1;\n            else flag = 2;\n            notifyAll();\n        }\n        \n    }\n\n    public synchronized void even(IntConsumer printNumber) throws InterruptedException {\n        int numOfEven = n/2;\n        while(numOfEven-- > 0){\n        \twhile(flag != 2) {\n        \t\twait();\n        \t}\n            printNumber.accept(++count);\n            lastPrintedEven = true;\n            flag = 0;\n            notifyAll();\n        }\n    }\n\n    public synchronized void odd(IntConsumer printNumber) throws InterruptedException {\n        int numOfOdd = n - n/2;\n        while(numOfOdd-- > 0){\n        \twhile(flag != 1) {\n        \t\twait();\n        \t}\n            printNumber.accept(++count);\n            lastPrintedEven = false;\n            flag = 0;\n            notifyAll();\n        }\n    }\n}\n```
['Java']