Skip to content

Commit 61a62df

Browse files
committed
Solution to count number of vowels and consonants in a String
1 parent 485ecb2 commit 61a62df

1 file changed

Lines changed: 34 additions & 0 deletions

File tree

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package Strings;
2+
3+
import java.util.ArrayList;
4+
5+
public class VowelsAndConsonants {
6+
public static void main(String[] args) {
7+
8+
ArrayList<Integer> listWithCountOfVowelsAndConsonants = solve("interviewbit");
9+
System.out.println(listWithCountOfVowelsAndConsonants);
10+
11+
}
12+
13+
static ArrayList<Integer> solve(String A) {
14+
int countOfVowels = 0;
15+
int countOfConsonants = 0;
16+
17+
int lengthOfString = A.length();
18+
19+
ArrayList<Integer> listWithCountOfVowelsAndConsonants = new ArrayList<Integer>();
20+
21+
for (int i = 0; i < lengthOfString; i++) {
22+
if (A.charAt(i) == 'a' || A.charAt(i) == 'e' || A.charAt(i) == 'i' || A.charAt(i) == 'o' || A.charAt(i) == 'u'){
23+
countOfVowels++;
24+
}else{
25+
countOfConsonants++;
26+
}
27+
}
28+
listWithCountOfVowelsAndConsonants.add(countOfVowels);
29+
// listWithCountOfVowelsAndConsonants.add(Integer.valueOf(" "));
30+
listWithCountOfVowelsAndConsonants.add(countOfConsonants);
31+
32+
return listWithCountOfVowelsAndConsonants;
33+
}
34+
}

0 commit comments

Comments
 (0)