[Java] Faster than 100% with synchronized
\nclass ZeroEvenOdd {\n    private int n;\n    private int i;\n    \n    public ZeroEvenOdd(int n) {\n        this.n = n;\n        this.i = 0;\n    }\n    \n   
```\nclass ZeroEvenOdd {\n    private int n;\n    private int i;\n    \n    public ZeroEvenOdd(int n) {\n        this.n = n;\n        this.i = 0;\n    }\n    \n    synchronized boolean get(int type, IntConsumer printNumber) {\n        if (i >= 2 * n) \n            return false;\n        if (type == 0 && i % 2 == 0)\n            printNumber.accept((i++) * 0);\n        else if (type == 1 && i % 4 == 1)\n             printNumber.accept( (i++) / 2 + 1);\n        else if (type == 2 && i % 4 == 3)\n             printNumber.accept( (i++) / 2 + 1);\n        return true;\n    }\n\n    // printNumber.accept(x) outputs "x", where x is an integer.\n    public void zero(IntConsumer printNumber) throws InterruptedException {\n        while (get(0, printNumber))\n            Thread.yield();\n    }\n\n    public void even(IntConsumer printNumber) throws InterruptedException {\n        while (get(2, printNumber))\n            Thread.yield();\n    }\n\n    public void odd(IntConsumer printNumber) throws InterruptedException {\n        while (get(1, printNumber))\n            Thread.yield();\n    }\n}\n```
[]