[INCORRECT SOLUTION][JAVA] Using semaphores
\nclass DiningPhilosophers {\n\n    Semaphore[] sems;\n    public DiningPhilosophers() {\n        this.sems = new Semaphore[5];\n        for (int i = 0; i < 5; 
```\nclass DiningPhilosophers {\n\n    Semaphore[] sems;\n    public DiningPhilosophers() {\n        this.sems = new Semaphore[5];\n        for (int i = 0; i < 5; i++) {\n            sems[i] = new Semaphore(1);\n        }\n    }\n\n    public void wantsToEat(int philosopher,\n                           Runnable pickLeftFork,\n                           Runnable pickRightFork,\n                           Runnable eat,\n                           Runnable putLeftFork,\n                           Runnable putRightFork) throws InterruptedException {\n        Semaphore left = sems[philosopher];\n        Semaphore right = (philosopher == 0) ? sems[4] : sems[philosopher - 1];\n        \n        if (philosopher % 2 == 0) {\n            left.acquire();\n            pickLeftFork.run();\n            right.acquire();\n            pickRightFork.run();\n        } else {\n            right.acquire();\n            pickRightFork.run();\n            left.acquire();\n            pickLeftFork.run();\n        }\n        \n        eat.run();\n        \n        if (philosopher % 2 == 0) {\n            putRightFork.run();\n            right.release();\n            putLeftFork.run();\n            left.release();\n        } else {\n            putLeftFork.run();\n            left.release();\n            putRightFork.run();\n            right.release();\n        }\n    }\n}\n```
[]