S
S
Sevlar2019-10-16 00:45:47
Java
Sevlar, 2019-10-16 00:45:47

A two-dimensional checkerboard array?

I'm just learning Java and immediately ran into a dead end in a task.
It is necessary to display a two-dimensional array in the form of a chessboard, but not simply, but in this form:
5da63cff066dc356938283.png
I know how to display a two-dimensional array in the form of a board, but alternating each cell, but this does not work. I guess I should use if and modulo division... help!
Here is my output:

int[][] mas = new int[24][24];
for(int i = 0; i < mas.length; i++) {
  for(int j=0; j < mas.length; j++) {
    if((i+j)%2 == 0) mas[i][j] +=1;
    System.out.print(" " + mas[i][j]);
  }
  System.out.println();
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
dollar, 2019-10-16
@Sevlar

if((Math.floor(i*0.25)+Math.floor(j*0.25))%2 == 0) mas[i][j] +=1;

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question