Skip to content

Commit 2d2b9f7

Browse files
committed
Count the vowels
1 parent 756d401 commit 2d2b9f7

File tree

1 file changed

+65
-0
lines changed

1 file changed

+65
-0
lines changed
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
package com.java.strings;
2+
3+
/*
4+
* Count the Vowels
5+
* ------------------
6+
*
7+
* A vowel is a syllabic speech sound pronounced
8+
* without any stricture in the vocal tract.
9+
* Vowels are one of the two principal classes of
10+
* speech sounds, the other being the consonant.
11+
* Vowels vary in quality, in loudness and also in quantity.
12+
*
13+
* The letters a, A, e, E, i, I, o, O, u and U are called vowels.
14+
* The other letters in the alphabet are called consonants.
15+
*
16+
*
17+
* say the string is "Hello"
18+
* the vowels are {e, o}
19+
* Count is 2
20+
*
21+
* say the string is "Tamil"
22+
* the vowels are {a, i}
23+
* Count is 2
24+
*
25+
* say the string is "why"
26+
* there are no Vowels in this word
27+
* Count is 0
28+
*/
29+
30+
public class CountVowels {
31+
public static void main(String[] args) {
32+
// String line = "Java Interview Programs";
33+
// String line = "Hello World!";
34+
String line = "Rhythm";
35+
int count = 0;
36+
37+
System.out.println("Given String is :"+line);
38+
line = line.toLowerCase();
39+
for(char ch : line.toCharArray()){
40+
switch (ch) {
41+
case 'a':
42+
case 'e':
43+
case 'i':
44+
case 'o':
45+
case 'u':
46+
count++;
47+
break;
48+
default:
49+
break;
50+
}
51+
}
52+
System.out.println("Number of Vowels are :"+count);
53+
}
54+
}
55+
/*
56+
OUTPUT
57+
Given String is :Java Interview Programs
58+
Number of Vowels are :8
59+
60+
Given String is :Hello World!
61+
Number of Vowels are :3
62+
63+
Given String is :Rhythm
64+
Number of Vowels are :0
65+
*/

0 commit comments

Comments
 (0)