Problem Statement
A chessboard pattern is a pattern that satisfies the following conditions:
- The pattern has a rectangular shape.
- The pattern contains only the characters '.' (a dot) and 'X' (an uppercase letter X).
- No two symbols that are horizontally or vertically adjacent are the same.
- The symbol in the lower left corner of the pattern is '.' (a dot).
You are given two ints rows and columns. Write a method that computes the chessboard pattern with these dimensions, and returns it in a String[]. The elements of the return value correspond to rows of the pattern. Specifically, the first character of the last element of the return value represents the lower left corner (see example 0).
Definition
- Class:
- ChessboardPattern
- Method:
- makeChessboard
- Parameters:
- int, int
- Returns:
- String[]
- Method signature:
- String[] makeChessboard(int rows, int columns)
- (be sure your method is public)
Constraints
- rows will be between 1 and 50, inclusive.
- columns will be between 1 and 50, inclusive.
Examples
8
8
Returns: {"X.X.X.X.", ".X.X.X.X", "X.X.X.X.", ".X.X.X.X", "X.X.X.X.", ".X.X.X.X", "X.X.X.X.", ".X.X.X.X" }A standard chessboard. Note that the last element starts with a dot.1
20
Returns: {".X.X.X.X.X.X.X.X.X.X" }A single row is a special case of a rectangle.5
1
Returns: {".", "X", ".", "X", "." }And so is a single column.5
13
Returns: {".X.X.X.X.X.X.", "X.X.X.X.X.X.X", ".X.X.X.X.X.X.", "X.X.X.X.X.X.X", ".X.X.X.X.X.X." }