
Output: Vowel Percentage: 50%.

import java.io.*;
import java.util.*;
import java.text.*;
import java.util.regex.*;
public class FindPercentage{
public static void main(String[] args){
try{
double count=0,vowel=0;
BufferedReader br=new BufferedReader(new FileReader(new File("C:/hello.txt")));
String ss="";
StringBuffer buffer=new StringBuffer();
while((ss=br.readLine())!=null){
buffer.append(ss);
}
String st = buffer.toString();
String str = st.replaceAll("[?!.]", "");
StringTokenizer tokenizer = new StringTokenizer(str);
String s = "";
while(tokenizer.hasMoreTokens()) {
s = tokenizer.nextToken().toLowerCase();
if((s.startsWith("a")) || (s.startsWith("e"))||(s.startsWith("i")) || (s.startsWith("o"))|| (s.startsWith("u"))) {
vowel++;
}
count++;
}
System.out.println("Total Number of words: "+count);
System.out.println("No of words that starts with vowel: "+vowel);
double value=vowel/count;
double percentage=value*100;
DecimalFormat df=new DecimalFormat("##.##");
System.out.println("Vowel Percentage: "+df.format(percentage));
}
catch(Exception e){
System.out.println(e);
}
}
}
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.