Java examples for Collection Framework:Array Algorithm
Adds each value of the first array with the corresponding value of the second one.
//package com.java2s; public class Main { /**/*from w w w . ja v a 2 s . c o m*/ * 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 = 0; i < result.length; i++) { result[i] = first[i] + second[i]; } return result; } }