JAVA Program to Calculate Number of Vowel in String

JAVA Program to Calculate Number of Vowel in String:

import java.io.*;
import java.lang.*;
class vowel
{
 public static void main(String args[])
 {
  String s="This is string";
  int cnt=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')
         cnt=cnt+1;
  }
  System.out.println("No of vowels are:"+cnt);
 }
}

OUTPUT:

No of vowels are:3

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.