-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path03-Vowels-Consonants.java
More file actions
50 lines (37 loc) · 1.27 KB
/
Copy path03-Vowels-Consonants.java
File metadata and controls
50 lines (37 loc) · 1.27 KB
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
import java.util.Scanner;
public class VowelsConsonants
{
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
System.out.print("Enter the number of strings in the array: ");
int n = sc.nextInt();
sc.nextLine(); // consume newline
String[] arr = new String[n];
int totalVowels = 0;
int totalConsonants = 0;
System.out.println("Enter the strings:");
for (int i = 0; i < n; i++)
{
arr[i] = sc.nextLine();
for (int j = 0; j < arr[i].length(); j++)
{
char ch = Character.toLowerCase(arr[i].charAt(j));
if (ch >= 'a' && ch <= 'z')
{
if (ch == 'a' || ch == 'e' || ch == 'i' || ch == 'o' || ch == 'u')
{
totalVowels++;
}
else
{
totalConsonants++;
}
}
}
}
System.out.println("Total Vowels across all strings: " + totalVowels);
System.out.println("Total Consonants across all strings: " + totalConsonants);
sc.close();
}
}