Version without JavaScript, read-only: workshops, quizzes and running code are not available here. Full version · Catalogue · Sign in
Sequence
Adding until past 100 (while)
Core exercise
Write sommeJusquaDepasser100() that adds 1 + 2 + 3 + … with a while loop, and returns the first sum that strictly exceeds 100.
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) {
System.out.println(sommeJusquaDepasser100());
}
public static int sommeJusquaDepasser100() {
// TODO : une boucle while
return 0;
}
}
The core exercise is validated in the workshop, which requires JavaScript.
Hint 1
Two variables: the sum and the next number to add. The loop continues as long as the sum is less than or equal to 100.