[問題] 矩陣翻轉的問題

看板java作者時間14年前 (2011/03/05 09:55), 編輯推噓0(004)
留言4則, 3人參與, 最新討論串1/2 (看更多)
ACM的練習題 輸入說明 : 第一行會有兩個數字,分別為 列(row)<100 和 行(column)<100,緊接著就是這個矩陣的 內容 輸出說明 : 直接輸出翻轉後的矩陣 我的答案 : //a015: 矩陣的翻轉 import java.util.Scanner; public class a015 { public static void main(String[] args) { Scanner sin = new Scanner(System.in); int a,b; a = sin.nextInt(); b = sin.nextInt(); int number[][] = new int[a][b]; for(int row =0;row<a;row++){ for(int commun=0;commun<b;commun++){ number[row][commun] = sin.nextInt(); } } for(int commun=0;commun<b;commun++){ for(int row=0;row<a;row++){ System.out.print(number[row][commun]+ " "); } System.out.println(); } } } 想法是直接將他的行跟列數字顛倒就好,不過跑到RE 不知道為什麼會這樣@@ -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 111.83.163.233

03/05 11:34, , 1F
矩陣不一定是方陣唷 你想想3x5矩陣轉過來是5x3
03/05 11:34, 1F

03/05 11:42, , 2F
對不起 我犯傻了 請無視我orz
03/05 11:42, 2F

03/05 12:22, , 3F
一個比較無關的事,你的 column 拼錯了
03/05 12:22, 3F

03/05 19:10, , 4F
英文不好~XD 看了一下它錯誤的內容是說索引超過
03/05 19:10, 4F
文章代碼(AID): #1DSPW9o5 (java)
文章代碼(AID): #1DSPW9o5 (java)