-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCountCharacters.java
More file actions
33 lines (26 loc) · 959 Bytes
/
Copy pathCountCharacters.java
File metadata and controls
33 lines (26 loc) · 959 Bytes
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
import java.util.Scanner;
public class CountCharacters {
public static void main(String[] args) {
Scanner scn = new Scanner(System.in);
String str = scn.nextLine();
int vowels = 0, consonants = 0, digits = 0, special = 0;
for (char ch : str.toCharArray()) {
if(Character.isLetter(ch)){
ch = Character.toLowerCase(ch);
if(ch == 'a' || ch == 'e' || ch == 'i' || ch == 'o' || ch == 'u'){
vowels++;
}else{
consonants++;
}
}else if(Character.isDigit(ch)){
digits++;
}else{
special++;
}
}
System.out.println("Vowels = " + vowels);
System.out.println("Consonants = " + consonants);
System.out.println("Digits = " + digits);
System.out.println("Special Characters = " + special);
}
}