[Java] Simple solution using two semaphores
The solution uses two semaphores which correspond to the foo and bar methods. \n- We initialize the foo semaphore with a single permit to permit the thread to i
The solution uses two semaphores which correspond to the foo and bar methods. \n- We initialize the foo semaphore with a single permit to permit the thread to immediately acquire it and print foo. \n- The bar semaphore is initialized without a permit and requires something to increment the number of permits to be consumed. When we reach the bar method, it is blocked by ```bar.acquire()``` as there are no available permits. A permit is only available after we release it in the foo method\n- Logic is reflected in foo with the acquire/release logic\n```\nclass FooBar {\n\n    private int n;\n    private Semaphore foo;\n    private Semaphore bar;\n\t\n    public FooBar(int n) {\n        this.n = n;\n        this.foo = new Semaphore(1);\n        this.bar = new Semaphore(0);\n    }\n\n    public void foo(Runnable printFoo) throws InterruptedException {\n        \n        for (int i = 0; i < n; i++) {\n            \n        \t// printFoo.run() outputs "foo". Do not change or remove this line.\n            foo.acquire();\n        \tprintFoo.run();\n            bar.release();\n        }\n    }\n\n    public void bar(Runnable printBar) throws InterruptedException {\n        \n        for (int i = 0; i < n; i++) {\n            \n            // printBar.run() outputs "bar". Do not change or remove this line.\n            bar.acquire();\n        \tprintBar.run();\n            foo.release();\n        }\n    }\n}\n```
['Java']