Task 1

mail@pastecode.io avatar
unknown
java
14 days ago
889 B
2
Indexable
Never
Scanner sc = new Scanner(Main.class.getResourceAsStream("Matrix.txt"));
int nm = sc.nextInt();
for(int tc = 0;tc < nm;tc++){
    int row = sc.nextInt();
    int column = sc.nextInt();
    int [][] matrix = new int[row][column];
    int [][] transposeMatrix = new int[column][row];
    int val;
    for(int i = 0; i < row;i++){
        for(int j = 0;j < column;j++){
            val = sc.nextInt();
            matrix[i][j] = val;
            transposeMatrix[j][i] = val;
        }
    }

    System.out.println("M:");
    for(int i = 0;i<row;i++){
        for(int j = 0;j < column;j++){
            System.out.print(matrix[i][j] + "\t");
        }
        System.out.println();
    }
    System.out.println("M':");
    for(int i = 0;i<column;i++){
        for(int j = 0;j<row;j++){
            System.out.print(transposeMatrix[i][j] + "\t");
        }
        System.out.println();
    }
}
Leave a Comment