Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

import java.util.List;

public class Main {
    /**
     * Calculeaza deviatia medie de la media pentru datele primite
     *
     * @param data
     * @return deviatia medie
     */
    public static double computeAverageFluctuations(List<Double> data) {
        double sum = 0;
        int index = 0;
        double media = 0;
        double max = 0;

        if (data.isEmpty()) {
            return 0;
        }

        for (Double i : data) {
            sum = sum + i;
        }

        media = sum / data.size();
        double dev = 0;

        for (Double i : data) {
            dev += Math.abs(media - i);
        }
        return dev / data.size();
    }
}