For an Assignment I have to create a Five in a Row Game with a print Method. So basically my Idea is that the Method goes through the whole two dimensional Array and everytime there is a 0 it adds a "-" to the String row instead. When there is 1 or 2 it adds the Number. When the [j] Array is finished it prints the whole row and initializes the row anew. Terminal is another Class which was given to us to print everything in the Class.
The Problem is the whole Method doesn't print anything at all and I don't know where the Problem could be.
public static void print() {
String row = "";
for (int i = 0; i < board.length; i++) {
for (int j = 0; j < board[i].length; j++) {
if (board[i][j] == 0) {
row += "-";
} else {
row += (char) (board[i][j]);
}
if (j == board[i].length) {
Terminal.printLine(row);
row = "";
}
}
}
}
Terminal? Also note that sincej < board[i].length, it will never be equal to it, move your print to after the inside for loopif(j == board[i].length)should beif(j == board[i].length - 1). Or, as phflack said, move it after the inner for loop.