Sunday, 18 October 2020

Count the number of vowels in a string.

import java.util.*;
public class VOWELstring
{
    public static void main(String args[])
    {
        Scanner sc = new Scanner(System.in);
        System.out.println("enter a string");
        String n= sc.nextLine();
        int a = n.length();
        int s= 0;
        for(int i = 0;i<a;i++)
        {
            char c=n.charAt(i);
            if(c=='a'||c=='e'||c=='i'||c=='o'||c=='u'||c=='A'||c=='E'||c=='I'||c=='O'||c=='U')
            {
             s=s+1;
             }
       }
        System.out.println(s);
    }
}


Output:
enter a string
bluej
2

No comments:

Post a Comment