Ver Mensaje Individual
  #1 (permalink)  
Antiguo 12/12/2013, 03:10
SilverDante
 
Fecha de Ingreso: diciembre-2013
Mensajes: 36
Antigüedad: 10 años, 5 meses
Puntos: 1
Pregunta Invertir una matriz

A la hora de pasar los datos a la matriz invertida por el método "invertMatriz", no funciona.

Código:
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package invertirmatriz;
import java.util.*;
/**
 *
 * @author mati
 */
public class InvertirMatriz {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        Scanner teclado=new Scanner(System.in);
        int n=0, m=0;
        
        System.out.println("Filas que tendrá la matriz.");
        n=teclado.nextInt();
        
        System.out.println("Columnas que tendrá la matriz.");
        m=teclado.nextInt();
        
        int[][] mxn = new int[n][m];
        int[][] destino = new int[m][n];
        
        introMatriz(mxn, n, m);
        muestraMatriz(mxn);
        destino=invertMatriz(mxn, n, m);
        muestraMatriz(destino);
    }
    
    public static void introMatriz(int [][]mxn, int n, int m){
        int i, j;
            for (i = 0; i < n; i++) {
            for (j = 0; j < m; j++) {
                mxn[i][j] = (int)(Math.random()*9 + 1);
                }
            }
    }
    
    public static void muestraMatriz(int [][]m){
        int i, j;        
        for(i=0;i<m.length;i++) {
            System.out.print("\n");
            for(j=0;j<m[i].length;j++){
                System.out.print(m[i][j]+" ");
            }
        }
        System.out.print("\n");
    }
    
    public static int[][] invertMatriz(int [][]mxn, int n, int m){
        
        int[][] destino = new int[m][n];
        
        for(int fil=0;fil<n;fil++){
            for(int col=0;col<m;col++){
                
                destino[fil][col]=mxn[col][fil];
        }
        }
        return destino;        
    
        }
}