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 {

    public static double getAverage(List<Integer> list) {
        if (list == null || list.size() == 0)
            return 0;
        double total = 0;
        int size = list.size();
        for (Integer i : list) {
            if (i == null || i.intValue() <= 0) {
                size--;
                continue;
            }
            total += i;
        }
        if (size <= 0) {
            return 0;
        }
        return total / size;
    }
}