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 maxima de la media pentru datele primite
     *
     * @param data
     * @return deviatia maxima de la medie
     */
    public static double computeFluctuations(List<Double> data) {
        double sum = 0;
        int index = 0;
        double media = 0;
        double max = 0;

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

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

        media = sum / data.size();

        for (Double i : data) {
            Double difference = Math.abs(media - i);
            if (max < difference) {
                max = difference;
            }
        }
        return max;
    }
}