-
Notifications
You must be signed in to change notification settings - Fork 0
/
Vowels_Consonants.txt
37 lines (32 loc) · 946 Bytes
/
Vowels_Consonants.txt
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
import java.util.Scanner;
class Vowels_Consonants
{
private boolean isVowel(char ch)
{
ch = Character.toLowerCase(ch);
return ch == 'a' || ch == 'e' || ch == 'i' || ch == 'o' || ch == 'u';
}
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
Vowels_Consonants ob = new Vowels_Consonants();
System.out.print("Enter a string :- ");
String str = sc.nextLine();
int length = str.length();
int vowels = 0;
int consonants = 0;
for(int i = 0 ; i < length ; ++i)
{
if(ob.isVowel(str.charAt(i)))
{
++vowels;
}
else if(Character.isLetter(str.charAt(i)))
{
++consonants;
}
}
System.out.println("No. of Vowels = " + vowels);
System.out.println("No. of Consonants = " + consonants);
}
}