Version without JavaScript, read-only: workshops, quizzes and running code are not available here. Full version · Catalogue · Sign in
Sequence
Sum of an array
Core exercise
Write somme(int[] tableau) that returns the sum of the elements. An empty array gives 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("somme : " + somme(notes));
}
public static int somme(int[] tableau) {
// TODO
return 0;
}
}
The core exercise is validated in the workshop, which requires JavaScript.
Hint 1
The loop for (int valeur : tableau) walks through the elements when you do not need the index.