-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathContarVogais.java
More file actions
42 lines (35 loc) · 1.13 KB
/
Copy pathContarVogais.java
File metadata and controls
42 lines (35 loc) · 1.13 KB
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import java.util.Scanner;
public class ContarVogais {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Digite uma palavra: ");
String palavra = sc.nextLine();
int a = 0, e = 0, i = 0, o = 0, u = 0;
for (int indice = 0; indice < palavra.length(); indice++) {
char letra = palavra.charAt(indice);
if (letra == 'a') {
a += 1;
} else if (letra == 'e') {
e += 1;
} else if (letra == 'i') {
i += 1;
} else if (letra == 'o') {
o += 1;
} else if (letra == 'u') {
u += 1;
}
}
if (a >=1) {
System.out.println("Vogal a: " + a);
} if (e >=1) {
System.out.println("Vogal e: " + e);
}if (i >=1) {
System.out.println("Vogal i: " + i);
} if (o >=1) {
System.out.println("Vogal o: " + o);
}if (u >=1) {
System.out.println("Vogal u: " + u);
}
sc.close();
}
}