2015-02-07 62 views
-2

如果您試圖顯示您的二維數組沿着列向下移動,並且出現超出界限的異常,那麼解決此問題的最佳方法是什麼?你會拋出異常嗎?先謝謝你!以列作爲外部循環打印多維數組

/*print out the array contents going down the columns from the first column to the last*/ 
for (int col=0;col<stuff.length; col++) { 
    for (int row=0;row<stuff[col].length;row++) { 
     System.out.print(stuff[row][col]); System.out.print(" "); 
    } 
    System.out.println(); 
} 
+0

「我試圖張貼我的代碼爲圖像」你爲什麼要這麼做?爲什麼不把它作爲文本發佈? – Pshemo 2015-02-07 22:42:04

回答

1

變化ROW和COL數組中:

for (int row=0;col<stuff.length; row++) { 
    for (int col=0;row<stuff[row].length;col++) { 
     System.out.print(stuff[row][col]); System.out.print(" "); 
    } 
    System.out.println(); 

}