Find the percentage of words which starts with a vowel in a file

Ads
 

Find the percentage of words which starts with a vowel in a file

  1. Question: Find the percentage of words which starts with a vowel in a file. Ex: Input: Contents of File1- There is an endless loop in the program.

Output: Vowel Percentage: 50%.

View Answers

April 28, 2011 at 2:56 PM

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);
        }
    }
}

Ads









Related Tutorials/Questions & Answers:
Find the percentage of words which starts with a vowel in a file
Find the percentage of words which starts with a vowel in a file   Question: Find the percentage of words which starts with a vowel in a file. Ex: Input: Contents of File1- There is an endless loop in the program. Output: Vowel
find the first character is vowel or not
find the first character is vowel or not  hi friend, can u plz send me javascript code for find the wether the first character is a vowel or not. 2) check wether the last character is same as the first character or not 3) check
Advertisements
tO FIND UNIQUE WORDS IN A FILE USING HASHMAP
tO FIND UNIQUE WORDS IN A FILE USING HASHMAP  import java.util....())); } System.out.println("Number of unique words in file "+cc...() { // create a HashMap to store unique combination of words
how to find which user has modified the file
how to find which user has modified the file  how to find which user has modified the file
accept sentence from user and print all word starts with vowel and end with consonent
accept sentence from user and print all word starts with vowel and end with consonent  Write a program to accept a sentence. Print all the words that starts with vowel and end with a consonant. e.g. input by user "the purpose
vowel
vowel  display all the vowel from word/string   import java.util.*; class DisplayVowels { public static void main(String[] args) { Scanner input=new Scanner(System.in); System.out.print("Enter
display co-occurrence words in a file
display co-occurrence words in a file  how to write java program for counting co occurred words in the file
display co-occurrence words in a file
display co-occurrence words in a file  how to write java program for counting co occurred words in the file
program to display all words in the file in the sorted order without duplicates
program to display all words in the file in the sorted order without duplicates  I want a java program which accepts a file from user and displays all words in the file in the sorted order without duplicates
java program to insert data into a file and count the number of words from the file???????
java program to insert data into a file and count the number of words from the file???????  java program to insert data into a file and count the number of words from the file
Display non-duplicate words from file
object is then passed to StringTokenizer which broke the text of file into words...Display non-duplicate words from file In this tutorial, you will learn how to read a text file and display non-duplicate words in ascending order. The given
display all words containing the letter which i gave as input...
display all words containing the letter which i gave as input...  If i enter any character,it have to display the names which having that character..write a program using java example(output) Enter any character: a Names: Abi
How to find a config file in spring project
How to find a config file in spring project  how to find configuration file in the spring project
Java latest file
Java latest file In this section, you will learn how to find the file which is generated or modified at last. Description of code: To find the last modified file, we have used the Comparator interface that compare the files 
Map words to line number in text file and show occurence
Map words to line number in text file and show occurence  hi i want to Map words to line number in text file and show occurrence of word in java coding
which is good hadoop file system commands tutorial
which is good hadoop file system commands tutorial  Hi, I am learning hadoop file system commands and trying to find all commands of hadoop with examples. which is good hadoop file system tutorial? Thanks   Hi
which is good hadoop file system commands tutorial
which is good hadoop file system commands tutorial  Hi, I am learning hadoop file system commands and trying to find all commands of hadoop with examples. which is good hadoop file system tutorial? Thanks   Hi
Find the date of the file before the file has been modified
Find the date of the file before the file has been modified  Hi, may i know is it possible to find the date of the file before the file has been modified?   hi friend, you can get the date of last modified file using
Program to count the number of unique words in a file using HashMap
Program to count the number of unique words in a file using HashMap  ...[]) throws FileNotFoundException { File f = new File("C:/547647/word...()); System.out.println("The number of unique words: "+uniqueValues.size
Program to find no of metrics in a file ----- Java code
Program to find no of metrics in a file ----- Java code  Hi Friends, I got a task to calculate the metrics of a program, like to find... the no of SELECT and INSERT statements but unable to find tablewise. E.G Table
find zip file length lessthen 5MB
find zip file length lessthen 5MB  import java.io.BufferedReader... File folder = new File(source); if(folder.exists... :"); detination=readkeyboard.readLine(); File[] files
java string vowel program
java string vowel program  java string vowel program   Please visit the following links: Display the word that begins with vowel Java Count Vowels
putting words to line number form a java file/test file and show occurrence
putting words to line number form a java file/test file and show occurrence  hi all i want putting words to line number form a java file and show occurrence but i cant use mapping method i can only use the LinkedList
Which extension i use for save hibernate file.
Which extension i use for save hibernate file.   Please give me answer that which extension i use for save the hibernate file and how i run that file as well as complie that file.   hi friend, Naming convention
find out in servlet which button was clicked on an html page
find out in servlet which button was clicked on an html page  i have two buttons on my jsp page... and i want two call two seperate codes in a servlet on pressing of those 2 buttons.. how do i find out which button was clicked so
storing records which of a file into a table of mssql database
storing records which of a file into a table of mssql database  I have a requirement like this, A file contains some records with headers same as column names of a table. I have to store those records into a table
How to read the contents in a file which is of input type file
How to read the contents in a file which is of input type file  I have a jsp page wherein i have to passs the file as input and read the contentsn of a file in servlet. upload.jsp <FORM METHOD=POST ENCTYPE="multipart/form
find jar file name from multiple set of jar files
find jar file name from multiple set of jar files   I would like to find jar file name from multiple set of jar files where the given class name√Ę‚?¨¬?com.rational.ft.util.debug√Ę‚?¨¬
ModuleNotFoundError: No module named 'vowel-versificon'
ModuleNotFoundError: No module named 'vowel-versificon'  Hi, My... named 'vowel-versificon' How to remove the ModuleNotFoundError: No module named 'vowel-versificon' error? Thanks   Hi, In your
in unix which command is used to sort the lines of data in a file in reverse order
in unix which command is used to sort the lines of data in a file in reverse order  in unix which command is used to sort the lines of data in a file... the lines of data in a file in reverse order
Create an HTML file AddCookies.html which contains four text boxes
Create an HTML file AddCookies.html which contains four text boxes  Create an HTML file AddCookies.html which contains four text boxes .When user enters the values in these text boxes and press the submit button, the values

Ads