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

Sequence

Average of 5 integers typed in

Core exercise

Write moyenneDeCinqEntiers() that reads 5 integers from the keyboard, stores them in an array, then prints their average. Create the Scanner inside the method.

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

Starting code

Exercices.java

import java.util.Scanner;

public class Exercices {

    public static void main(String[] args) {
        moyenneDeCinqEntiers();
    }

    public static void moyenneDeCinqEntiers() {
        Scanner sc = new Scanner(System.in);
        // TODO : lire 5 entiers, les stocker, afficher la moyenne
    }
}

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

Hint 1

A for loop of 5 iterations that fills tableau[i] = sc.nextInt(). For the average, think of integer division: (double) total / 5.