It's a ternary statement combined with the modulus operator.
Ternary structure:
condition ? action-true : action-false
this results in your case to
i % 2 == 0 ? Color.black : Color.white
Or written fully:
if(i % 2 == 0) {
singleSquare.setBackground(Color.black);
} else {
singleSquare.setBackground(Color.white);
}
Modulus:
i % 2
returns the remainder after divising i
by 2. In your case this will result in an alternation between black and white (by adding 1 each iteration it will alternatively evaluate to true
and false
).