1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
|
public class Main {
public static int nbOccurrence(String [] tabString, char caractere){
int counti = 0;
int countj = 0;
for(int i = 0; i < tabString.length; i++){
for(int j = 0; j < tabString[i].length(); j++){
if (tabString[i].charAt(j) == caractere){
countj ++;
}
}
counti = counti + countj;
countj = 0;
}
return counti;
}
public static void main(String[] args) {
String[] tab = new String[] {"essai", "test", "exemple", "example"};
int occurrence = nbOccurrence(tab,'e');
System.out.println("Le caractère 'e' apparaît " + occurrence + " fois." );
}
} |
Partager