I wonder if it's possible to fill a multidimensional boolean Array with a string.
Let's imagine we are making Battleship Game something like:
public static void main(String[] args) {
boolean[][] board = new boolean[5][5];
board[3][2] = true;
board[0][0] = true;
for (boolean[] line : board
) {
System.out.println(Arrays.toString(line));
}
}
Now is it possible to change all the Values to be " [ ] " if its false and to be " [X] " if its true but still keep the boolean values?
ifstatements...You can't change the values of thebooleanarray toStringsbut you can printStringsinstead ofbooleanvalues.booleans.replaceAll("true", "[X]").replaceAll("false", "[ ]")on output string.replaceAlland not simplyreplace?Cor any but don't forget this is java where Boolean only accepts either "true" or "false" neither a string ,char or int.. But u may get help of any collection class.. I am sure u will got d solution. Thanks