Program to find the number of vowels in a string using Java
public class Vowels {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
String str[]={"a,e,i,o,u"};
int j=0;
System.out.println("enter the string");
Scanner sc=new Scanner(System.in);
String str1=sc.nextLine();
for(int i=0;i<str1.length();i++)
{
char ch=str1.charAt(i);
String temp=Character.toString(ch);
if(temp.equalsIgnoreCase("a" )|| temp.equalsIgnoreCase("e")||temp.equalsIgnoreCase("i")||temp.equalsIgnoreCase("o")||temp.equalsIgnoreCase("u"))
{
j++;
}
}
System.out.println("No of vowels is"+j);
}
}
No comments:
Post a Comment