Computer Applications
Write a program to input a sentence and display the word of the sentence that contains maximum number of vowels.
Sample Input: HAPPY NEW YEAR
Sample Output: The word with maximum number of vowels: YEAR
Java
Java String Handling
Answer
import java.util.Scanner;
public class KboatMaxVowelWord
{
    public static void main(String args[]) {
        Scanner in = new Scanner(System.in);
        System.out.println("Enter a sentence:");
        String str = in.nextLine();
        
        str = str + " ";
        String word = "", mWord = "";
        int count = 0, maxCount = 0;
        int len = str.length();
        
        for (int i = 0; i < len; i++) {
            
            char ch = Character.toUpperCase(str.charAt(i));
            
            if (ch == 'A' ||
                ch == 'E' ||
                ch == 'I' ||
                ch == 'O' ||
                ch == 'U') {
                count++; 
            }
            
            if (ch == ' ') {
                if (count > maxCount) {
                    maxCount = count;
                    mWord = word;
                }
                word = "";
                count = 0;
            }
            else {
                word += ch;
            }
        }
        
        System.out.println("The word with maximum number of vowels: "
                            + mWord);
    }
}Variable Description Table
Program Explanation
Output

Answered By
Related Questions
- Write a program in Java to enter a sentence. Display the words which are only palindrome. 
 Sample Input: MOM AND DAD ARE NOT AT HOME
 Sample Output: MOM
 DAD
- Write a program to accept a sentence. Display the sentence in reversing order of its word. 
 Sample Input: Computer is Fun
 Sample Output: Fun is Computer
- Consider the sentence as given below: 
 Blue bottle is in Blue bag lying on Blue carpet
 Write a program to assign the given sentence to a string variable. Replace the word Blue with Red at all its occurrence. Display the new string as shown below:
 Red bottle is in Red bag lying on Red carpet
- Write a program to accept a word and convert it into lower case, if it is in upper case. Display the new word by replacing only the vowels with the letter following it. 
 Sample Input: computer
 Sample Output: cpmpvtfr