-
Notifications
You must be signed in to change notification settings - Fork 61
/
CountVowels.java
69 lines (64 loc) · 1.49 KB
/
CountVowels.java
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package com.java.strings;
/*
* Count the Vowels
* ------------------
*
* A vowel is a syllabic speech sound pronounced
* without any stricture in the vocal tract.
* Vowels are one of the two principal classes of
* speech sounds, the other being the consonant.
* Vowels vary in quality, in loudness and also in quantity.
*
* The letters a, A, e, E, i, I, o, O, u and U are called vowels.
* The other letters in the alphabet are called consonants.
*
*
* say the string is "Hello"
* the vowels are {e, o}
* Count is 2
*
* say the string is "Tamil"
* the vowels are {a, i}
* Count is 2
*
* say the string is "why"
* there are no Vowels in this word
* Count is 0
*
* Words without vowels are
* sky, spy, try, fly, lynch, myth, dry, why, sync, shy, ply,
* by, cry, crypt, fry, gym, psych, spy
*/
public class CountVowels {
public static void main(String[] args) {
// String line = "Java Interview Programs";
// String line = "Hello World!";
String line = "Rhythm";
int count = 0;
System.out.println("Given String is :"+line);
line = line.toLowerCase();
for(char ch : line.toCharArray()){
switch (ch) {
case 'a':
case 'e':
case 'i':
case 'o':
case 'u':
count++;
break;
default:
break;
}
}
System.out.println("Number of Vowels are :"+count);
}
}
/*
OUTPUT
Given String is :Java Interview Programs
Number of Vowels are :8
Given String is :Hello World!
Number of Vowels are :3
Given String is :Rhythm
Number of Vowels are :0
*/