I have been surfing StackOverflow for about an hour looking for an answer to this really easy question, but it seems that none apply to this specific circumstance.
import java.awt.Color;
public class Question15 {
public void fillCheckerBoard(Color[][] board){
for(int n = 0; n < board.length; n++){
for(int k = 0; k < board[0].length; k++){
if((k%2==0 && n%2 ==0)||(k%2==1 && n%2 ==1)){
board[n][k] = Color.black;
}
else{
board[n][k] = Color.white;
}
if(board[k][n] == Color.black){
System.out.print("x");
}
else
System.out.print(" ");
}
}
}
public static void main(String[] args) {
Color [][] a = new Color [4][5];
Question15 b = new Question15();
b.fillCheckerBoard(a);
System.out.print(b);
}
}
The method createCheckerBoard takes in a Color [][] array and creates a checkerboard to the dimensions specified within the 2D array.
In the main method I have created a 2D Color array called "a", and a new object called "b". I want to test out the fillCheckerBoard method out, using "a" as the input. Once "a" has been modified, I want to print "a" out to see if my fillCheckerBoard works. I made a Question15 object because as far as I know a void method needs an object in order to work.
What I have done in the void method only returns an error when I try to run the program. How can I test if my method can actually print out a checker board?