I'm trying to work through a project which creates a chessboard layout. The only part I can't get my head around is this line
if (row == 0)
singleSquare.setBackground( i % 2 == 0 ? Color.black : Color.white );
else if (row != 0)
singleSquare.setBackground( i % 2 == 0 ? Color.white : Color.black );
It seems to be 2 nested if
statements but can anyone explain the logic behind it? It basically makes one square white then next square black etc for and 8,8 grid but I can't understand the logic. Thanks
Edit - Should have been more precise. What does this part mean?
i % 2 == 0 ? Color.black : Color.white
I will swap between 1 and 0 as the loop goes through I understand. What does the question mark do that makes it change from black to white?