-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathChaînesExo7.2.java
More file actions
27 lines (26 loc) · 928 Bytes
/
ChaînesExo7.2.java
File metadata and controls
27 lines (26 loc) · 928 Bytes
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
26
27
public class Main {
public static void main(String[] args) {
int vowels = 0;
int consonnes = 0;
int words = 0;
int phrases = 0;
String sentence = "Les amis de Martine sont communistes. Ils avaient rendez-vous à la grange.";
for (int i = 0 ; i < sentence.length() ; i++) {
char ch = sentence.charAt(i);
if (ch == 'a'|| ch == 'e'|| ch == 'i' ||ch == 'o' ||ch == 'u'||ch == 'y') {
vowels++;
}
// Si espace ou apostrophe ou trait d'union :
if (ch == ' ' || ch == 39 || ch == 45) {
words++;
}
if (ch == 46) {
phrases++;
}
else {
consonnes++;
}
}
System.out.println("Voyelles : " + vowels + ", consonnes : " + consonnes + ", mots : " + words + ", phrases : " + phrases );
}
}