Computer

WAP to count the number of vowels in a String?

WAP to count the number of vowels in a String?

import java.util.Scanner;
Vowels
{
public static void main (String args[])
{
Scanner sc = new Scanner (System.in);
System.out.println (“Enter the String”);
String str = sc.nextLine ();
char[]chars=str.toCharArray();
int count= 0;
for (char cha : chars)
{
switch (cha)
{
case ‘a’:
case ‘e’:
case ‘i’:
case ‘o’:
case ‘u’:
count ++;
break ;
}
}
System.out.println(“Number of vowels in string=” + count);
}
}

WAP to count and print the number of vowels Output

 

Related Articles

One Comment

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top button
Study Worms Would you like to receive notifications on latest updates? No Yes

Adblock Detected

Please consider supporting us by disabling your ad blocker