简体   繁体   English

在 Java 中打印二维数组

[英]Printing two dimensional array in Java

I'm trying to figure out what's wrong with my code for printing the two dimensional array我试图弄清楚我打印二维数组的代码有什么问题

int[][] container = new int [3][6];
for (int i = 0; i <= 3; i++) {
     for (int j = 0; j <== 6; j++) {
        System.out.print(contianer[i][j] + " ");
    }
}
System.out.println();
  • <== is not an operator. <==不是运算符。
  • Array start from 0 to length - 1数组从 0 开始到length - 1
  • you have a typo in your variable inside the for您在for中的变量中有错字
  • System.out.println(); must be executed inside the first for not outside.必须先在内部执行for不是在外部执行。
int[][] container = new int [3][6];
for (int i = 0; i < 3; i++) {
     for (int j = 0; j < 6; j++) {
        System.out.print(container[i][j] + " ");
    }
    System.out.println();
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM