Question: You are trying to create a chessboard representation using the alphabetical uppercase letters O and X . The O ' s represent the lighter spaces

You are trying to create a chessboard representation using the alphabetical uppercase letters O and X. The O's represent the lighter spaces while the X's represent the darker spaces. Be careful NOT to use zero (0) in your code!
Desired pattern:
OXOXOXOX
XOXOXOXO
OXOXOXOX
XOXOXOXO
OXOXOXOX
XOXOXOXO
OXOXOXOX
XOXOXOXO
public class LabChallenge {
public static void main(String args[]){
String[][] chessboard = new String[8][8];
//add code below this line
//add code above this line
for (int row =
0; row < chessboard.length; row++){
for (int col =0; col < chessboard[0].length; col++){
if (col == chessboard[0].length -1){
System.out.println(chessboard[row][col]);
}
else {
System.out.print(chessboard[row][col]);
}
}
}
}
}
Requirement:
Your program cannot make any changes to the existing code in the program. If you do, you will not earn any credit for this challenge. If you accidentally delete any existing code, you can copy the original code shown above back into your program.
Hint: It is probably much easier to use nested for loops in your code to populate the 2D array with either O's or X's than to go through each (row, column) index to modify the elements.
Thank you

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!