Able to print chessboard in both odd and even cases, but its throwing The program needs to display the elements of the array on the screen error
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) {
//write your code here
Scanner sc = new Scanner(System.in);
int x = sc.nextInt();
sc.close();
array = new char[x][x];
for (int i = 0; i < array.length; i++) {
for (int j = 0; j < array[i].length; j++) {
if (i%2 == 0) {
if (i%2 == 0 && j%2 == 0) {
array[i][j] = '#';
}else if (i%2 ==0 && j%2 == 1) {
array[i][j] = ' ';
}
}
else{
if (!(i%2 == 0) && j%2 == 0) {
array[i][j] = ' ';
}else if (i%2 ==1 && j%2 == 1) {
array[i][j] = '#';
}
}
}
}
for (int i = 0; i < array.length; i++) {
for (int j = 0; j < array[i].length; j++) {
System.out.print(array[i][j] + " ");
}
System.out.println();
}
}
}