Chessboard Cell Color
Programming Basics · Java
TASK
Problem
Read chessboard coordinates `row` and `col` from 1 to 8. Print `BLACK` if the cell is black and `WHITE` otherwise. Cell (1,1) is black.
EXAMPLE
Example
1 1
BLACK
LIMITS
Constraints
1 ≤ row, col ≤ 8
LEARN
Theory for this problem
+
The core idea of **Chessboard Cell Color** is to model the requested operation directly: Read chessboard coordinates `row` and `col` from 1 to 8. Print `BLACK` if the cell is black and `WHITE` otherwise. Cell (1,1) is black. The reference solution uses `Scanner` for input. Keep only the state needed for this result, choose numeric types that cover the stated bounds, and preserve the exact input/output contract. This makes the solution easier to verify on boundary cases and avoids unrelated work.
NEED HELP?
Hints
+
['Follow the statement for **Chessboard Cell Color** literally and identify the smallest state needed to produce its output.', 'The reference solution relies on `Scanner` for input; test the smallest allowed input and one boundary case from the constraints.']
ANSWER
Solution
+
// CodeMaster — Chessboard Cell Color
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int row = sc.nextInt();
int col = sc.nextInt();
boolean black = (row + col) % 2 == 0;
System.out.println(black ? "BLACK" : "WHITE");
}
}