---
# System prepended metadata

title: Java_Cmoney_ft9101_矩陣反轉
tags: [Cmoney_Java題目]

---

---
tags: Cmoney_Java題目
---
Java_Cmoney_ft9101_矩陣反轉
===

![](https://i.imgur.com/OjrvT69.png)


1.主程式
---
矩陣反轉方式
1. 內外的 m 和 n 交換
2. 輸出的 2D 矩陣 `matrix[j][i]` (原本為 `matrix[i][j]` )

==如果是該列的最後一個數列後面不要有空白==

```java=
import java.util.Scanner;


public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int[][] matrix = new int[n][m];
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                matrix[i][j] = sc.nextInt();
            }
        }
        for (int i = 0; i < m; i++) {
            for (int j = 0; j < n; j++) {
                if (j == n - 1)
                    System.out.print(matrix[j][i]);
                else
                    System.out.print(matrix[j][i] + " ");
            }
            System.out.println();
        }
    }
}

```
