Task1 bos

mail@pastecode.io avatar
unknown
java
15 days ago
1.1 kB
1
Indexable
Never
        Scanner sc = new Scanner(Main.class.getResourceAsStream("Matrix.txt"));
        int mmk = sc.nextInt();
        for(int tc = 0;tc < mmk;tc++){
            int r = sc.nextInt();
            int c = sc.nextInt();
            int [][] matrix = new int[r][c];
            int [][] transposeMatrix = new int[c][r];
            int val;
            for(int i = 0; i < r;i++){
                for(int j = 0;j < c;j++){
                    val = sc.nextInt();
                    matrix[i][j] = val;
                    transposeMatrix[j][i] = val;
                }
            }

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