Count the number of vowels in a sentences
Problem to count the number of vowels in a string.Vowels are (a,e,i,o,u).
Example-1:
Input : s = "mycrazycoding" Output : 3 Explain : Total number of vowels in an string are 3(a,o,i).
Example-2:
Input : s = "helloworld" Output : 3 Explain : Total number of vowels in an string are 3(e,o,o).
Solution
public class Main { public static void main(String [] args) { String s = "mycrazycoding"; int count = 0; for(int i = 0; i < s.length(); i++) { if(s.charAt(i)=='a'||s.charAt(i)=='e'||s.charAt(i)=='i'||s.charAt(i)=='o'||s.charAt(i)=='u'||s.charAt(i)=='A'||s.charAt(i)=='E'||s.charAt(i)=='I'||s.charAt(i)=='O'||s.charAt(i)=='U') { count++; } } System.out.print(count); } }
n = "mycrazycoding" a = "aeiou" k = 0 for i in range(len(n)): if(n[i] in a): k += 1 print(k)
Output
3