A simple Java program to the knighstravails problem