Java Array Add addArray(double[] array1, double[] array2)

Here you can find the source of addArray(double[] array1, double[] array2)

Description

add Array

License

Open Source License

Declaration

public static double[] addArray(double[] array1, double[] array2) 

Method Source Code

//package com.java2s;
/**/*from  w  w  w  .j ava  2  s. c  o m*/
* Copyright (c) Acroquest Technology Co, Ltd. All Rights Reserved.
* Please read the associated COPYRIGHTS file for more details.
*
* THE SOFTWARE IS PROVIDED BY Acroquest Technolog Co., Ltd.,
* WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
* BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDER BE LIABLE FOR ANY
* CLAIM, DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING
* OR DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES.
*/

public class Main {

    public static double[] addArray(double[] array1, double[] array2) {
        if (array1.length != array2.length) {
            throw new IllegalArgumentException("The dimensions have to be equal!");
        }

        double[] result = new double[array1.length];
        assert array1.length == array2.length;
        for (int i = 0; i < array1.length; i++) {
            result[i] = array1[i] + array2[i];
        }

        return result;
    }
}

Related

  1. addArray(int[] a, int p)
  2. addArray(int[] a, int[] b)
  3. addArray(Object[] Old, Object[] New)
  4. addArray(Object[][] first, Object[][]... more)