I am trying to output a checker pattern into a two dimensional array. How do I assign two characters in order to do this? Note array is a square [5][5] Please help.
// Takes two symbols and places them in alternate cells of board
public static char[][] placeSymbols(char charY, char charZ) {
// Generate first symbol character
String input2;
Scanner inCharY = new Scanner(System.in);
System.out.println("Enter first character: ");
input2 = inCharY.nextLine();
charY = input2.charAt(0);
System.out.println(charY);
// Generate second symbol character
String input3;
Scanner inCharZ = new Scanner(System.in);
System.out.println("Enter second character: ");
input3 = inCharZ.nextLine();
charZ = input3.charAt(0);
System.out.println(charZ);
// Insert characters into array
char square[][];
square = new char[size][size];
for (int row = 0; row < size; row++) {
for (int col = 0; col < square[row].length; col++) {
square[row][col] = charY; // Here assigning one character fills all the places
System.out.print(" " + square[row][col]);
}
System.out.println(" ");
}
return square;
}
Thanks very much for any help,
Jems