Version without JavaScript, read-only: workshops, quizzes and running code are not available here. Full version · Catalogue · Sign in

Sequence

Average of an array

Core exercise

Write moyenne(int[] tableau) that returns the average as a double. An empty array gives 0.0.

A workshop goes here: you write and run code in it. It requires JavaScript.

Starting code

Exercices.java

public class Exercices {

    public static void main(String[] args) {
        int[] notes = { 12, 15, 8, 19 };
        System.out.println("moyenne : " + moyenne(notes));
    }

    public static double moyenne(int[] tableau) {
        // TODO : attention a la division entiere
        return 0;
    }
}

The core exercise is validated in the workshop, which requires JavaScript.

Hint 1

Classic trap: somme / tableau.length between two ints performs integer division. Convert: (double) somme / tableau.length.