Answer the question
In order to leave comments, you need to log in
How to swap columns in java two dimensional array?
Hello. I have a two dimensional array int[][] board. I need to swap any columns in it. I tried to swap the lines (code below), everything worked out, but in the case of strings, the program does not require you to write the second []. And what about columns? I don’t understand what to indicate in the first parentheses, they can’t be skipped, can they?
int[][] boardCopy = new int[board.length][board.length];
boardCopy[0] = board[0];
board[0] = board[2];
board[2] = boardCopy[0];
Answer the question
In order to leave comments, you need to log in
Unlike rows, which you can copy all at once, you can't copy columns
one by one.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question