[英]Java 2d String array fill the array
String[][] work = new String[3][];
thats work 多数民众赞成在工作
work[0] = new String[3];
work[0][0]=" !!! ";
work[0][1]=" !!! ";
work[0][2]=" !!! ";
work[1] = new String[3];
work[1][0]=" !!! ";
work[1][1]=" !!! ";
work[1][2]=" !!! ";
work[2] = new String[3];
work[2][0]=" !!! ";
work[2][1]=" !!! ";
work[2][2]=" !!! ";
thats dont work for me i dont know where is mistake Exception in thread "AWT-EventQueue-0" java.lang.ArrayIndexOutOfBoundsException: 3 多数民众赞成在我身上不工作,我不知道哪里出错了线程“ AWT-EventQueue-0”中的异常java.lang.ArrayIndexOutOfBoundsException:3
for(int i=0;i<13;i++){
work[i]= new String[3];
}
for(int i=0;i<13;i++){
for(int j=0;j<3;j++){
work[i][j]=" !!! ";
}
}
for(String[] x: work){
for(String e : x){
System.out.println(e);
}System.out.println();
}
mistake is here String[][] work = new String[13][]; 错误在这里String [] [] work = new String [13] []; 3->13
3-> 13
You should change 你应该改变
for(int i=0;i<13;i++) {
to 至
for(int i=0;i<work.length;i++) {
This will save you from similar typos. 这样可以避免您遇到类似的错字。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.