Java examples for Collection Framework:Array Algorithm
Calculates the power in a sample as sum of the squares of the absolute values of all samples.
//package com.java2s; public class Main { /**//from w w w .j a va 2 s. com * Calculates the power in a sample as sum of the squares of the absolute values of all samples. * @param sample * @return */ public static double getPower(double[] sample) { double power = 0; for (int i = 0; i < sample.length; i++) { power += Math.pow(Math.abs(sample[i]), 2); } return power; } }