2015-02-07 41 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(); 

}