java solution using concurrency
class FooBar {\n    private int n;\n    Semaphore   foo;\n    Semaphore  bar;\n    public FooBar(int n) {\n        this.n = n;\n        foo=new Semaphore(1);\n 
class FooBar {\n    private int n;\n    Semaphore   foo;\n    Semaphore  bar;\n    public FooBar(int n) {\n        this.n = n;\n        foo=new Semaphore(1);\n        bar =new Semaphore (0);\n    }\n\n    public void foo(Runnable printFoo) throws InterruptedException {\n        \n        for (int i = 0; i < n; i++) {\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            bar.acquire();\n        \tprintBar.run();\n            foo.release();\n        }\n    }\n}
['Java']