How can I reverse the order of a matrix?

0

For example, if I have [1,2,3,4,5,6,7,8,9] , how do I get the opposite [9.8, 7,6,5,4,3,2,1]

int n = 0, m = 0, c = 0, aux = 0;
String lista = "";
int j = 0, i = 0;

n = Integer.parseInt(JOptionPane.showInputDialog("Escriba la cantidad de filas"));
m = Integer.parseInt(JOptionPane.showInputDialog("Escriba la cantidad de columnas"));

int matriz[][] = new int[n][m];

for (i = 0; i < n; i++) {// llenado automatico
    for (j = 0; j < m; j++) {
        c = c + 1;
        matriz[i][j] = c;
    }
}
    
asked by Steven Camargo 28.08.2017 в 02:28
source

1 answer

0

Simply run it backwards, start from the size of the matrix that are n and m -1, go to 0 and decrease it for example:

n = 2 m = 2

i = 2-1; i> = 0; i-- therefore i = 1; i> = 0; i-- j = 2-1; j > = 0; j-- therefore j = 1; j > = 0; j -

n = Integer.parseInt(JOptionPane.showInputDialog("Escriba la cantidad de 
    filas"));
m = Integer.parseInt(JOptionPane.showInputDialog("Escriba la cantidad de 
    columnas"));

int matriz[][] = new int[n][m];

for (i= n-1; i >= 0; i--) {// llenado automatico
    for (j = m-1; j >= 0; j--) {
        c = c + 1;
        matriz[i][j] = c;
    }
}
    
answered by 28.08.2017 / 03:04
source