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


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


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)


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


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