集册 Java实例教程 比较两个双数组,如果两个数组都不为空,并且长度相等且包含相等的值,则返回true。

比较两个双数组,如果两个数组都不为空,并且长度相等且包含相等的值,则返回true。

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

329
提示:您可在线编辑运行本教程的实例 - 运行实例,去试试!
比较两个双数组,如果两个数组都不为空,并且长度相等且包含相等的值,则返回true。
/* 
 来自 
*时   代    Java - nowjava.com*/


//package com.nowjava;


public class Main {

    public static void main(String[] argv) throws Exception {

        double[] a1 = new double[] { 34.45, 35.45, 36.67, 37.78, 37.0000,

                37.1234, 67.2344, 68.34534, 69.87700 };

        double[] a2 = new double[] { 34.45, 35.45, 36.67, 37.78, 37.0000,

                37.1234, 67.2344, 68.34534, 69.87700 };

        System.out.println(arraysAreEqual(a1, a2));

    }


    /**

     * <p>Compare two double arrays and return true if both not null, and are of equal length and contain equal values.</p>

     *

     * @param   a1   first array

     * @param   a2   second array

     * @return      true if equal

     */

    static public boolean arraysAreEqual(double[] a1, double[] a2) {

        //System.err.println("ArrayCopyUtilities.arraysAreEqual(): a1 = "+a1);

        //System.err.println("ArrayCopyUtilities.arraysAreEqual(): a2 = "+a2);

        boolean result = true;

        if (a1 == null || a2 == null || a1.length != a2.length) {

            result = false;

        } else {
        /**
         from
        * 时 代 J a v a 公 众 号 
        **/

            for (int i = 0; i < a1.length; ++i) {

                //if (a1[i] != a2[i]) {

                
展开阅读全文