【问题标题】:Printing the multidimensional array with column as the outer loop打印以列为外循环的多维数组
【发布时间】:2015-02-07 22:29:02
【问题描述】:

如果您尝试在列中显示二维数组并且遇到超出范围的异常,那么解决该问题的最佳方法是什么?你会抛出异常吗?先感谢您!

/*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(); 
} 

【问题讨论】:

  • “我试图将我的代码作为图像发布”你为什么要这样做?为什么不直接将其发布为文本?

标签: java arrays multidimensional-array


【解决方案1】:

更改数组中的行和列:

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(); 

} 

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-08-12
    • 2015-06-12
    • 1970-01-01
    • 2014-06-13
    • 2021-03-21
    • 1970-01-01
    • 2013-04-15
    相关资源
    最近更新 更多