给一个非矩形数组(Nonrectangular Arrays)
Nonrectangular Arrays(非矩形数组)
public class Test {
public static void main(String[] args) {
String[ ] str;
str=new String[2];
str[0]="aaa";
str[1]="bb";
String[ ] str1;
str1=new String[]{"aaa","bbb"};
// 假如写成下一句,就报这个错。Cannot define dimension expressions when an array initializer is provided
// str1=new String[2]{"aaa","bbb"};
System.out.println(str1[0]+str1[1]);
String[][] x = new String[3][];
x[0]=new String[]{"hello","马克-to-win"};
x[1]=new String[]{"are","you","fine"};
x[2]=new String[]{"ok"};
for(int i=0; i<3;i++){
for(int j=0;j<x[i].length;j++){
System.out.println("x["+i+"]["+j+"]"+" is "+x[i][j]);
}
}
}
}
更多内容请见原文,原文转载自:https://blog.csdn.net/qq_44639795/article/details/103124325