lyconquest123 于 2014.12.12 17:09 提问

public class HelloWorld {
public static void main(String[] args) {

``````    // 定义两行三列的二维数组并赋值
String [][] names = new String[2][3];
names = {{"tom","jack","mike"},{"zhangsan","lisi","wangwu"}};

// 通过二重循环输出二维数组中元素的值
for (int i = 0; i < names.length    ; i++) {

for (int j = 0; j < names[i].length; j++) {
System.out.println(names[i][j]);
System.out.println(                  );
}

System.out.println();
}
}
``````

}

6个回答

xsm_lyf   2014.12.12 17:15

= =没有names={{}}这样纸赋值数组的

jinyan1993 写法不对 建议看一下数组的基础知识

xsm_lyf 放在new String后面成功是因为他有够着函数

ZWXXL   2014.12.12 17:29

ZWXXL   2014.12.12 17:30

public static void main(String[] args) {
// 定义两行三列的二维数组并赋值
String [][] names = new String[2][3];
String [][] temp = {{"tom","jack","mike"},{"zhangsan","lisi","wangwu"}};
names = temp;

``````    // 通过二重循环输出二维数组中元素的值
for (int i = 0; i < names.length    ; i++) {

for (int j = 0; j < names[i].length; j++) {
System.out.println(names[i][j]);
System.out.println(                  );
}

System.out.println();
}
}
``````
ZWXXL   2014.12.12 17:30

public static void main(String[] args) {
// 定义两行三列的二维数组并赋值
String [][] names = new String[2][3];
String [][] temp = {{"tom","jack","mike"},{"zhangsan","lisi","wangwu"}};
names = temp;

``````    // 通过二重循环输出二维数组中元素的值
for (int i = 0; i < names.length    ; i++) {

for (int j = 0; j < names[i].length; j++) {
System.out.println(names[i][j]);
System.out.println(                  );
}

System.out.println();
}
}
``````
lxq_xsyu   2014.12.14 11:48

``````        // 定义两行三列的二维数组并赋值
//String [][] names = new String[2][3];
String[][] names = {{"tom","jack","mike"},{"zhangsan","lisi","wangwu"}};
``````

`````` // 定义两行三列的二维数组并赋值
String [][] names = new String[][]{{"tom","jack","mike"},{"zhangsan","lisi","wangwu"}};
``````

u010664312   2014.12.14 21:10

String [][] names = new String[2][3];
String [][]temp = {{"tom","jack","mike"},{"zhangsan","lisi","wangwu"}};
names=temp;