Average ArrayList

less than 1 minute read

The code has been modified slightly and now uploaded to the site.

Question

<— Return Home

Main.java

import java.util.ArrayList;

public class Main {
    public static void main(String[] args) {
        ArrayList<Integer> list = new ArrayList<Integer>();
        // list.add(1);
        // list.add(6);
        // list.add(8);
        list.add(5);
        list.add(1);
        list.add(7);
        list.add(3);
        average(list);
    }

    public static void average(ArrayList<Integer> list){
        // int initial = list.get(0);
        double combine = 0;
        for (int i = 0; i < list.size(); i++){
            combine += list.get(i);
        }
        combine /= list.size();
        System.out.println(combine);
    }
}

<— Return Home