I tested the input number from 1 to 5 without any error. Still, I cannot go through the validation and I cannot figure out what is wrong. The result looks like ok, I got the n x n array initiated with '#". I appreciate any help to debug it.
package en.codegym.task.jdk13.task06.task0634;
import java.util.Scanner;
/*
Chess board
*/
public class Solution {
public static char[][] array;
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int n = scanner.nextInt();
array = new char[n][n];
for (int i = 0; i < n; i+=2) {
for (int j = 0; j < n; j+=2) {
array [i][j] = '#';
}
}
for (int i = 1; i < n; i+=2) {
for (int j = 1; j < n; j+=2) {
array[i][j] = '#';
}
}
for (int i = 0; i < n; i+=2) {
for (int j = 1; j < n; j+=2) {
array[i][j] = ' ';
}
}
for (int i = 1; i < n; i+=2) {
for (int j = 0; j < n; j+=2) {
array[i][j] = ' ';
}
}
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
System.out.print(array[i][j]);
}
System.out.println(" ");
}
}
}