Computer Science, asked by MegaStudents, 1 year ago

write a program to accept a string pass it to function freq(String x)the function find and print the frequency of each vowel

Attachments:

Answers

Answered by SkullCrusherFC
16
import java.util.Scanner;
class Vowels_frequency
{
public void Frequency(String s)
{
int a=0,e=0,I=0,o=0,u=0;
for(int i=0;i<=s.length();i++)
{
char c=s.charAt(i);
c=c.toLowerCase(c);
if(i==97)//ASCI value of a
a++;
else if(i==101)//ASCI value of e
e++;
else if(i==105)ASCI value of i
I++;
else if(i==111)//ASCI value of o
o++;
else if(i==117)//ASCI value of u
u++;
}
System.out.println("No.of times A="+a);
System.out.println("No.of times E="+e);
System.out.println("No.of times I="+I);
System.out.println("No.of times O="+o);
System.out.println("No.of times U="+u);
}
public static void main(String args[])
{
Scanner scan=new Scanner(System.in);
System.out.println("Enter a string:");
String s=scan.nextLine();//String input
Vowels_frequency Vf=new Vowels_frequency();//Object of class created
Vf.Frequency(s);//function called and string passed
}
}

MegaStudents: thanks for ur precious time to let me out of this problem
Similar questions