集册 Java实例教程 将第一个数组的每个值与第二个数组的相应值相加。

将第一个数组的每个值与第二个数组的相应值相加。

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

480
将第一个数组的每个值与第二个数组的对应值相加。
/**
时代Java - N o w  J a v a . c o m
**/


//package com.nowjava;


public class Main {

    /**

     * Adds each value of the first array with the corresponding

     * value of the second one.

     */

    public static double[] add(double[] first, double[] second) {

        if (first.length != second.length) {

            throw new IllegalArgumentException("Dimensions don't match! "

                    + first.length + " != " + second.length);

        }

        double[] result = new double[first.length];

        for (int i 
展开阅读全文