SImple Java Solution
\nclass FooBar {\n    private int n;\n    private volatile boolean isFoo = true;\n\n    public FooBar(int n) {\n        this.n = n;\n    }\n\n    public void fo
```\nclass FooBar {\n    private int n;\n    private volatile boolean isFoo = true;\n\n    public FooBar(int n) {\n        this.n = n;\n    }\n\n    public void foo(Runnable printFoo) throws InterruptedException {\n        for (int i = 0; i < n; i++) {\n            while (!isFoo);\n            \n        \t// printFoo.run() outputs "foo". Do not change or remove this line.\n        \tprintFoo.run();\n            \n            isFoo = false;\n        }\n    }\n\n    public void bar(Runnable printBar) throws InterruptedException {        \n        for (int i = 0; i < n; i++) {\n            while (isFoo);\n            \n            // printBar.run() outputs "bar". Do not change or remove this line.\n        \tprintBar.run();\n            \n            isFoo = true;\n        }\n    }\n}\n```
[]