Vowels:- a,e,i,o,u,A,E,I,O,U In this question, we have to count the number of consonants and vowels. How to Approach :- For this, we must traverse the whole string while traversing take a character and check whether it is a consonant or vowel. If it is a consonant increase the count of consonants by 1 otherwise increase the count of vowels by 1. Java 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 import java.util.Scanner; public class NumbersOfVowelsAndConsonants { public static void main (String[] args) { Scanner sc = new Scanner(System. in ); String str = sc. nextLine (); int vowels = 0 , consonants = 0 ; String lowerCase = str. toLowerCase (); for ( int i = 0 ; i <str. length (); i++) { char c = lowerCase. charAt (i); if (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u' ) ...
This blog contains coding/programming and interview questions of MNCs like TCS, Wipro, Infosys, Capgemini, Mindtree, Amazon, Google, Facebook, Flipkart, Cisco, HP, Dell, etc. with placement preparation guides.