JAVA基础学习笔记 day006_04二维数组


import java.util.Arrays;

public class Two_dimensional_array {
	public static void main(String[] args) {
		//二维数组的定义
		int twoDimArray[][] = new int[3][5];
		int[][] twoDimArray1 = {{1,3}, {22,56,47}, {0}};
		int[][] twoDimArray2 = new int[][]{{1,3}, {22,56,47}, {0}};
		
		
		double[][] dwa ;
		dwa = new double[][]{{1.0,3.1}, {22.4,56.7,47.8}, {0.0}};
		
		int[][] twoDimArray3;
		twoDimArray3 = new int[][]{{1,3}, {22,56,47}, {0}};
		
		//二维数组的下标访问
		int[][] test_dArray_index = {{1,3}, {22,56,47}, {0}};
//		test_dArray_index[1] == {22,56,47};
//		test_dArray_index[1][0] == 22; ==> {22,56,47}[0];
		
		//二维数组的遍历
		int[][] test_twoDimArray1 = {{1,3,7}, {22,56,47,4}, {0,1}};
		
		for(int i=0; i=0; i--){
//			Arrays.sort(Darr_test[i]);
//		}
		
//		Arrays.sort(Darr_test);
		
		System.out.println(Arrays.toString(Darr_test));
		for(int i=0; i=0; i--){
//			System.out.println(Arrays.toString(Darr_test[i]));
//		}
		
		//equals方法不能直接比较两个二维数组是否相等,因为它比较的是内存地址。
		int[][] arr_equal1 = {{79,3},{80,1,4,9},{7},{0,0,0}};
		int[][] arr_equal2 = {{79,3},{80,1,4,9},{7},{0,0,0}};
		boolean isEqual = Arrays.equals(arr_equal1, arr_equal2);
//		System.out.println(arr_equal1);
//		System.out.println(arr_equal2);
//		System.out.println("arr_equal1:"+Arrays.toString(arr_equal1));
//		System.out.println("arr_equal2:"+Arrays.toString(arr_equal2));
		System.out.println(isEqual);
		
		//fill方法不能直接用于二维数组
//		int[] arr_fill = new int[3];
//		int[] small_arr = new int[1];
//		Arrays.fill(arr_fill, small_arr);
		
		int[][] test_fill = new int[3][2];
		for(int i=0; i

 

你可能感兴趣的:(课程学习)