Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions