Computer Applications
Write a program to accept a sentence in mixed case. Find the frequency of vowels in each word and print the words along with their frequencies in separate lines.
Sample Input:
We are learning scanner class
Sample Output:
Word Frequency of vowels
We 1
are 2
learning 3
scanner 2
class 1
Java
Input in Java
28 Likes
Answer
import java.util.Scanner;
public class KboatVowelFrequency
{
public static void main(String args[]) {
Scanner in = new Scanner(System.in);
System.out.println("Enter a sentence ending with a space & terminating with (.):");
while (in.hasNext()) {
String orgWord = in.next();
String word = orgWord.toUpperCase();
if (word.equals("."))
break;
int vowelFreq = 0;
for (int i = 0; i < word.length(); i++) {
if (word.charAt(i) == 'A' ||
word.charAt(i) == 'E' ||
word.charAt(i) == 'I' ||
word.charAt(i) == 'O' ||
word.charAt(i) == 'U')
vowelFreq++;
}
System.out.println(orgWord + "\t\t" + vowelFreq);
}
}
}Variable Description Table
Program Explanation
Output

Answered By
10 Likes
Related Questions
Write a program (using scanner class) to generate a pattern of a token in the form of a triangle or in the form of an inverted triangle depending upon the user's choice.
Sample Input/Output:
Enter your choice 1
*
* *
* * *
* * * *
* * * * *Enter your choice 2
* * * * *
* * * *
* * *
* *
*In a competitive examination, a set of 'N' number of questions results in 'True' or 'False'. Write a program by using scanner class to accept the answers. Print the frequency of 'True' and 'False'.
Write a program by using scanner class to input a sentence. Display the longest word along with the number of characters in it.
Sample Input:
We are learning scanner class in JavaSample Output:
The longest word: learning
Number of characters: 8Write a program by using scanner class to input a sentence. Print each word of the sentence along with the sum of the ASCII codes of its characters.