Untitled

mail@pastecode.io avatar
unknown
java
2 years ago
625 B
2
Indexable
Never
public class Average {
    public static void main(String[] args) {

        int arr[] = { 1, 2, 3, 4, 5, 6, 1, 10 };
        int average = 0;
        int remainder = 0;
        int len = arr.length;

        for (int i = 0; i < len; i++) {
            int q = arr[i] / len; // division
            int r = arr[i] % len; // remainder
            average = average + q;
            remainder += r;
            if (remainder / len >= 1) {
                average = average + (remainder / len);
                remainder = remainder % len;
            }
        }
        System.out.println(average);
    }
}