Given two vectors adds them up and returns their sum - Java java.lang

Java examples for java.lang:Math Vector

Description

Given two vectors adds them up and returns their sum

Demo Code


//package com.java2s;

public class Main {
    /** //  www .  ja va  2s . co m
     * Given two vectors adds them up and returns their sum
     * @param first First vector which is to be added
     * @param second Second vector which is added to the first
     * @return Double[] containing the sum of the two vectors
     */
    public static <T> Double[] addVectors(T[] first, T[] second) {

        Double[] sum = new Double[first.length];

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

            sum[i] = (Double) first[i] + (Double) second[i];
        }

        return sum;
    }
}

Related Tutorials