Anda di halaman 1dari 3

Escribir una aplicacin llamado AplicacionMatriz2 que pida dos nmeros M y N y que despus pida los elementos de una

matriz de M renglones por N columnas, y que a partir de esta genere y despliegue otra matriz de N renglones por M columnas, donde cada elemento de la nueva matriz estar al revs que en la matriz original. La aplicacin debe funcionar como se ve en la grfica: matriz original 1234 5678 9 10 11 12 matriz al reves 12 9 6 3 11 10 8 7 5 4 2 1

esto es lo que tengo no se que hacer import java.io.*; public class AplicacionMatriz2 { public static void main(String[] args) throws IOException { // definiendo un objeto de entrada para tomar datos del teclado BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); System.out.print("Da Cuantos Reglones: "); int m = Integer.parseInt(in.readLine()); System.out.print("Da Cuantas Columnas: "); int n = Integer.parseInt(in.readLine()); int a[][] = new int[m][n]; int b[][] = new int [n][m] ; // pidiendo los datos del teclado de la matriz m System.out.println("Pidiendo Valores Matriz A"); for (int i = 0; i < a.length; i++) { for (int j = 0; j < a[0].length; j++) { System.out.print("Da elemento " + (i + 1) + " , " + (j + 1) + " : "); a[j] = Integer.parseInt(in.readLine()); } System.out.println(); } //desplegando la matriz a System.out.println("Matriz Original"); for (int i = 0; i < a.length; i++) { for (int j = 0; j < a[0].length; j++) { System.out.print(" " + a[j] + " "); } System.out.println(); } System.out.println();

System.out.println("Matriz Original"); for (int i = 0; i < b.length; i++) { for (int j = 0; j < b[0].length; j++) { b[j]=b[a.length-i-i][a.length-i-j]; System.out.print(" " + b[j] + " "); } //System.out.println(); } //System.out.println(); } }

En lnea

Leyer Moderador Desconectado Mensajes: 771

Re: ayuda Respuesta #1 en: 3 Mayo 2010, 06:39 Toma este metodo que hice pasale la matriz la cantidad maxima de columnas y filas y te retornara la matriz al revs. Cdigo 1. /** 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12. 13. Tmatriz[j1][j]=matriz[indexColumn][indexRows]; 14. 15. j++; }j1--; * @param matriz * @param maxColumn * @param maxRows * * @return */ public static int[][] proc(int [][]matriz,int maxColumn,int maxRows){ int Tmatriz[][] = new int[maxColumn][maxRows]; int j1=maxColumn-1; for(int indexColumn=0;indexColumn<maxColumn;indexColumn++){ for(int indexRows=maxRows1,j=0;indexRows>=0;indexRows--){

[]

16. 17. 18. 19. }

} return Tmatriz;

Anda mungkin juga menyukai