Java | Beat 85% | Simple wait and notify solution
Simple Wait and Notify logic. Please upvote \n\n~~~\nclass FooBar {\n    private int n;\n\n    public FooBar(int n) {\n        this.n = n;\n    }\n    \n    vol
Simple Wait and Notify logic. Please upvote \n\n~~~\nclass FooBar {\n    private int n;\n\n    public FooBar(int n) {\n        this.n = n;\n    }\n    \n    volatile boolean printF = true;\n\n    public  void foo(Runnable printFoo) throws InterruptedException {\n            for (int i = 0; i < n; i++) {\n                synchronized (this){\n                    if(!printF){\n                        this.wait();\n                    }\n                    printFoo.run();\n                    printF = false;\n                    this.notifyAll();\n                }\n            }\n    }\n\n    public  void bar(Runnable printBar) throws InterruptedException {\n        for (int i = 0; i < n; i++) {\n                synchronized (this){\n                    if(printF){\n                        this.wait();\n                    }\n                    printBar.run();\n                    printF = true;\n                    this.notifyAll();\n                }\n            }\n    }\n}\n~~~
['Java']