Wait and notify solution
The base thing of this solution is \'while\' operator in even and odd methods, thats why they are guranted wait while condition is true, but in zero method we d
The base thing of this solution is \'while\' operator in even and odd methods, thats why they are guranted wait while condition is true, but in zero method we do not need to use while because on every tact we need to insert 0 value\n\n# Code\n```java []\nclass ZeroEvenOdd {\n    private int n;\n    \n    public ZeroEvenOdd(int n) {\n        this.n = n;\n    }\n\n    private boolean zeroPrinted = false;\n    private boolean evenPrinted = false;\n    private boolean oddPrinted = false;\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 = 1; i <= n; i ++) {\n            if (zeroPrinted) {\n                wait();\n            }\n            if (i % 2 == 0) {\n                evenPrinted = false;\n                oddPrinted = true;\n            } else {\n                evenPrinted = true;\n                oddPrinted = false;\n            }\n            printNumber.accept(0);\n            zeroPrinted = true;\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 (evenPrinted) {\n                wait();\n            }\n            evenPrinted = true;\n            zeroPrinted = false;\n            printNumber.accept(i);\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 (oddPrinted) {\n                wait();\n            }\n            oddPrinted = true;\n            zeroPrinted = false;\n            printNumber.accept(i);\n            notifyAll();\n        }\n    }\n}\n```
['Java']