集册 Java实例教程 数组等于2D

数组等于2D

欢马劈雪     最近更新时间:2020-01-02 10:19:05

501
数组等于2D
//时 代      J a v a   公   众 号 - nowjava.com 提 供


//package com.nowjava;


public class Main {


    public static boolean equals2D(int[][] array1, int[][] array2) {


        if (array1.length != array2.length) {


            System.err.println("Array length mismatch.");

            return false;


        }// if(...)


        for (int i1 = 0; i1 < array1.length; i1++) {


            if (array1[i1].length != array2[i1].length) {


                System.err

                        .println("Array length ( of 2nd Dimension ) mismatch.");
/**from 时 代 J a v a**/

                return false;


            }// if(...)


            for (int i2 = 0; i2 < array1[i1].length; i2++) {


                if (array1[i1][i2] != array2[i1][i2]) {


                    System.err.println("Value mismatch.");

                    System.err.println("\t" + i1 + "," + i2 + "  "

                            + array1[i1][i2] + " != " + array2[i1
展开阅读全文