Version without JavaScript, read-only: workshops, quizzes and running code are not available here. Full version · Catalogue · Sign in
Sequence
Counting a letter
Core exercise
Write compterOccurrences(String texte, char lettre) that returns the number of times lettre appears in texte (case-sensitive).
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(compterOccurrences("anticonstitutionnellement", 't'));
}
public static int compterOccurrences(String texte, char lettre) {
// TODO
return 0;
}
}
The core exercise is validated in the workshop, which requires JavaScript.
Hint 1
Walk through the string with charAt(i), from 0 to texte.length() - 1. Compare chars with ==: they are not objects.