if i have a two dimensional array and want to make another arraythat is the reverse of the first array how to do this
Printable View
if i have a two dimensional array and want to make another arraythat is the reverse of the first array how to do this
Code:public class Test {
public static void main(String[] args) {
int[][] forward = {
{ 1, 2, 3, 4 },
{ 5, 6, 7, 8 }
};
int rows = forward.length;
int cols = forward[0].length;
int[][] reverse = new int[rows][cols];
for(int i = rows-1; i >= 0; i--) {
for(int j = cols-1; j >= 0; j--) {
reverse[rows-1-i][cols-1-j] = forward[i][j];
}
}
for(int i = 0; i < rows; i++) {
for(int j = 0; j < cols; j++) {
System.out.print(reverse[i][j]);
if(j < cols-1)
System.out.print(", ");
}
System.out.println();
}
}
}
thanks but how to make the colums rows and the rows colums without reversing
Hi You can find the code at:
forum4everyone.com - How to transpose an array
thanks alot for you
I love this site very much because there are many guys help me thanks to all of you