遍历数组的三种方法 foreach遍历二维数组输出?
foreach遍历二维数组输出?public class Tautog { //创建类public static void main(String[] args) { //主方法int arr2[][
foreach遍历二维数组输出?
public class Tautog { //创建类public static void main(String[] args) { //主方法int arr2[][] = { { 4, 3 }, { 1, 2 } } //定义二维数组System.out.println("数组中的元素是:") //提示信息for (int x[] : arr2) { //外层循环变量为一维数组for (int e : x) { //循环遍历每一个数组元素if (e == x.length) { //判断变量是二维数组中的最后一个元素System.out.print(e) //输出二维数组的最后一个元素} else //如何不是二维数组中的最后一个元素System.out.print(e "、") //输出信息}}}}JDK1.5以上才能