import java.util.Scanner;
public class Transpuesta {
public static void main(String[] arg) {
int x;
// int y;
Scanner s = new Scanner(System.in);
System.out.print("digite la dimencion de la matriz");
x = s.nextInt();
int m[][] = new int[x][x];
for (int i = 0; i < m.length; i++) {
for (int j = 0; j < m[0].length; j++) {
System.out.print("los valores de la matriz");
m[i][j] = s.nextInt();
}
}
System.out.println("matriz origunal");
for (int i = 0; i < m.length; i++) {
for (int j = 0; j < m[0].length; j++) {
System.out.print(m[i][j]);
}
System.out.println();
}
System.out.println("matriz transpuesta");
for (int i = 0; i < m.length; i++) {
for (int j = 0; j < m.length; j++) {
System.out.print(m[j][i]);
}
System.out.println();
}
}
}
comenten si tienen otra solución
ResponderEliminarimport java.util.Scanner;
ResponderEliminarpublic class Ejercicio3 {
public static void main(String[] arg) {
int x;
int y;
Scanner s = new Scanner(System.in);
System.out.println("Ingrese el numero de filas: ");
x = s.nextInt();
System.out.println("Ingrese el numero de columnas: ");
y = s.nextInt();
int m[][] = new int[x][y];
for (int i = 0; i < m.length; i++) {
System.out.println("Fila # " + (i+1) + " : ");
for (int j = 0; j < m[0].length; j++) {
System.out.println("Ingrese el valor # " + (j+1) +" : ");
m[i][j] = s.nextInt();
}
}
System.out.println("La matriz original: ");
for (int i = 0; i < m.length; i++) {
for (int j = 0; j < m[0].length; j++) {
System.out.print("[" + m[i][j] + "]");
}
System.out.println("");
}
System.out.println("La matriz transpuesta: ");
for (int i = 0; i < m[0].length; i++) {
for (int j = 0; j < m.length; j++) {
System.out.print("[" + m[j][i] +"]");
}
System.out.println("");
}
}
}