Count Vowels and Consonants

· unclassifiedUnclassifiedstrings

Count Vowels and Consonants

javamay contain transcription errors
import java.util.*;
class Main{
public static void main(String[] args){

Scanner sc = new Scanner(System.in);
String str = sc.nextLine().toLowerCase();
int vowels = 0, consonants = 0;
for(char ch : str.toCharArray()){
if(Character.isLetter(ch)){
if("aeiou".indexOf(ch) != -1)
vowels++;
else
consonants++;
}
}
System.out.println("Vowels: " + vowels);
System.out.println("Consonants: " + consonants);
}
}
← Count Sundays in N Days from a Given Start DayCount Vowels, Consonants, Spaces and Special Characters →
Report an issue with this question