#27391: 請問哪裡有問題 使用Java編寫


qqaz53122486@gmail.com (只是顆洋蔥)

學校 : 樹德科技大學
編號 : 122081
來源 : [218.173.146.170]
最後登入時間 :
2020-05-18 20:37:20
a015. 矩陣的翻轉 | From: [218.173.141.130] | 發表日期 : 2021-09-30 02:51

import java.util.*;
public class a015 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int row,column;
        row = sc.nextInt();
        column = sc.nextInt();
        int [][] chain = new int[row][column];
        while(sc.hasNext()) {
            for(int i=0;i<row;i++) {
                for(int j=0;j<column;j++) {
                    chain[i][j]=sc.nextInt();
                }
            }
            int [][] Newchain = new int[column][row];
            for(int i=0;i<column;i++) {
                for(int j=0;j<row;j++) {
                    Newchain[i][j]=chain[j][i];
                }
            }
            for(int i=0;i<column;i++) {
                for(int j=0;j<row;j++) {
                    System.out.print(Newchain[i][j]+" ");
                }
                System.out.println();
            }
        }
        sc.close();
    }
}
 
#27502: Re:請問哪裡有問題 使用Java編寫


cges30901 (cges30901)

學校 : 不指定學校
編號 : 30877
來源 : [101.136.203.77]
最後登入時間 :
2024-04-07 15:34:14
a015. 矩陣的翻轉 | From: [180.217.213.62] | 發表日期 : 2021-10-10 16:15

        row = sc.nextInt();
        column = sc.nextInt();
        int [][] chain = new int[row][column];


輸入有多組測資,每一組測資都包含列數和行數,所以這三行要放在while迴圈裡面

 
ZeroJudge Forum