3 回答
TA贡献2条经验 获得超23个赞
String[][] names={{"tom","jack","mike"},{"zhangsan","lisi","wangwu"}};
/String[][] names={{"tom","jack","mike"},{"zhangsan","lisi","wangwu"}};
//首先假设二维数组是[i,j] ,i从0到2,j从0到2
// 通过二重循环输出二维数组中元素的值
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();
}
// 通过二重循环输出二维数组中元素的值
for (int i = 0; i <names.length; i++) {
//外层循环,第一重
for (int j = 0; j < names[i].length; j++) {
//内层循环,第二重,i每+1,j 从0执行到i,因此执行[0,0] ,[1,0],[1,1],[2,0],[2,1],[2,2],就把所有单位元素遍历出来了
System.out.println(names[i][j]);
}
System.out.println();
}
TA贡献3593条经验 获得超0个赞
添加回答
举报