-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConstantCounter.java
More file actions
29 lines (21 loc) · 914 Bytes
/
ConstantCounter.java
File metadata and controls
29 lines (21 loc) · 914 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
28
29
import java.util.HashMap;
public class ConstantCounter{
public static void main(String[] args) {
String str = "Hello World I am Jay bhavsar";
HashMap<String,Integer> hashMap = CountConstant(str);
System.out.println("Total Constants are:"+hashMap.get("c"));
}
public static HashMap<String,Integer> CountConstant(String str){
str = str.toLowerCase();
System.out.println("Stringis:"+str);
HashMap<String,Integer> hashMap = new HashMap<String,Integer>();
hashMap.put("c", 0);
for (int j=0; j<str.length(); j++) {
if(str.charAt(j) != 'a' && str.charAt(j) != 'e' && str.charAt(j) != 'i'
&& str.charAt(j) != 'o' && str.charAt(j) != 'u' && str.charAt(j) != ' '){
hashMap.put("c",hashMap.get("c") + 1);
}
}
return hashMap;
}
}