public class HelloWorld { public static void main(String[] args) { // 定义两行三列的二维数组并赋值 String [][] names={{"tom","jack","mike"},{"zhangsan","lisi","wangwu"}}; // 通过二重循环输出二维数组中元素的值 for (String [] i:names) { for (String j:i) { System.out.println(j); } System.out.println(); } } }
使用foreach实现