package com.haoran.method; public class twoDemo { //写一个二维数组的遍历方法,并使用 public static void main(String[] args) { int[][]num={{1,2},{3,4},{5,6},{4,5}}; System.out.println(num.length+"\t"); System.out.println(num[1].length+"\t"); //元素个数依旧是4,元素又是数组,元素数组中元素的个数是2 //所以可以利用嵌套的方式进行遍历,先遍历第一个元素数组中的元素,然后第二个元素数组...以此类推 twoarray(num); } public static void twoarray(int[][] array){ for (int i = 0; i < array.length; i++) { for (int j = 0; j < array[i].length; j++) { System.out.print(array[i][j]+" "); } } } }
02-01