info@meritcampus.com    +91-85006-22255
...

In chess, assuming that the columns are numbered A to H and the rows are numbered 1 to 8. Find all the positions to which the camel can move. Assume that there is nothing else on the chess board.
NOTE: The list returned should be first sorted by columns and then by rows, so A4 comes before B1 and C7 comes before D5 etc.,

Input (Position) Output (Sorted List of Positions)
C2 [A4, B1, B3, D1, D3, E4, F5, G6, H7]
D4 [A1, A7, B2, B6, C3, C5, E3, E5, F2, F6, G1, G7, H8]
F8 [A3, B4, C5, D6, E7, G7, H6]
H1 [A8, B7, C6, D5, E4, F3, G2]

``` class FindCamelPositions {    public static void main(String s[])    {        ChessPosition camel = new ChessPosition('C', 2);        System.out.println("The positions which camel can move to: " + getPossiblePositions(camel));    } public static List<ChessPosition> getPossiblePositions(ChessPosition position) { //Write a code here to get possible positions to which a camel can move. } } class ChessPosition { char column; int row; public ChessPosition(char column, int row) { this.column = column; this.row = row; } @Override public String toString() { return column + "" + row; } } ```

Topic: Java ArrayList

0
Wrong
Score more than 2 points