Although my program is reading a number and the output data is according to the requested, the task keeps failing to pass testing. I always get the same error: "The program needs to read a number from the keyboard"- failed. I've tried both keyboard input methods, Scanner and InputStream and in both cases I get the same error.
"The array must be initialized with an appropriately-sized array". - Ok, passed;
"The array must be filled as outlined in the task conditions". - Ok, passed;
"The program needs to display elements of the array on the screen (see the example in the task conditions)". - Ok, passed.
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 < array.length; i++) {
for (int j = 0; j < array[1].length; j++) {
if (i % 2 == 0 && j % 2 == 0 || i % 2 != 0 && j % 2 != 0) {
array[i][j] = '#';
} else {
array[i][j] = ' ';
}
System.out.print(array[i][j]);
}
System.out.println();
}
}
}