多维数组
package array;public class ArrayDemo05 {public static void main(String[] args) {//[4][2] 面向对象/*1,2 array[0]2,3 array[1]3,4 array[2]4,5 array[3]*/int[][] array = {{1,2},{2,3},{3,4},{4,5}};for (int i = 0; i <array.length; i++) {for (int j = 0; j <array[i].length; j++) {System.out.println(array[i][j]);}}}//打印数组元素public static void prinArray(int[]arrays){for (int i = 0; i <arrays.length; i++) {System.out.println(arrays[i]+" ");}}}
Arrays类讲解
package array;import java.util.Arrays;public class ArrayDemo06 {public static void main(String[] args) {int[] a = {1, 2, 3, 4, 9090, 31231, 541, 3131};//System.out.println(a);//[I@4554617c//打印数组元素Arrays.toString//System.out.println(Arrays.toString(a));Arrays.sort(a);//数组进行排序:升序System.out.println(Arrays.toString(a));Arrays.fill(a,0);//数组填充System.out.println((Arrays.toString(a)));}//重复造轮子public static void printArray(int[] a) {for (int i = 0; i < a.length; i++) {if (i == 0) {System.out.print("[");}if (i == a.length-1) {System.out.print(a[i] + "]");} else {System.out.print(a[i] + ",");}}}
}