-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathVowelCounter.java
More file actions
39 lines (31 loc) · 1.22 KB
/
VowelCounter.java
File metadata and controls
39 lines (31 loc) · 1.22 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
import java.util.HashMap;
public class VowelCounter{
public static void main(String[] args) {
String str = "Hello World I am Jay bhavsar";
HashMap<String,Integer> hashMap = CountVowels(str);
System.out.println("hashMap:=="+hashMap);
}
public static HashMap<String,Integer> CountVowels(String str){
str = str.toLowerCase();
System.out.println("Stringis:"+str);
HashMap<String,Integer> hashMap = new HashMap<>();
hashMap.put("a", 0);
hashMap.put("e", 0);
hashMap.put("i", 0);
hashMap.put("o", 0);
hashMap.put("u", 0);
System.out.println("Size of string:"+str.length());
for (int j=0; j<str.length(); j++) {
switch (str.charAt(j)) {
case 'a' -> hashMap.put("a", hashMap.get("a") + 1);
case 'e' -> hashMap.put("e", hashMap.get("e") + 1);
case 'i' -> hashMap.put("i", hashMap.get("i") + 1);
case 'o' -> hashMap.put("o", hashMap.get("o") + 1);
case 'u' -> hashMap.put("u", hashMap.get("u") + 1);
default -> {
}
}
}
return hashMap;
}
}