Cumulative Sum Of Power in double array - Java java.lang

Java examples for java.lang:double Array

Description

Cumulative Sum Of Power in double array

Demo Code


//package com.java2s;

public class Main {
    public static double CumulativeSumOfPower(double[] data, int exp) {
        double Sum = 0;
        int size = data.length;
        for (int i = 0; i < size; i++) { //for each item in the array, we sum the result of its power by the exponent parameter 
            Sum = add(Sum, Power(data[i], exp));
        }/*from   w  ww. ja v  a2 s.  c om*/
        return Sum;
    }

    public static double add(double first, double second) {
        return first + second;
    }

    public static double Power(double base, int exponent) {
        return Math.pow(base, exponent);
    }
}

Related Tutorials