Write a program in Java to input a String and print that word which contains the highest number of vowels.
Example -
input - HAPPY NEW YEAR
output - YEAR
Don't Spam!!!
Share
Write a program in Java to input a String and print that word which contains the highest number of vowels.
Example -
input - HAPPY NEW YEAR
output - YEAR
Don't Spam!!!
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Required Answer:-
Question:
Solution:
Here is the program.
Explanation:
Output is attached.
Verified answer
Answer:
Here's it:
Explanation:
import java.util.Scanner;
public class Main {
public static void main(String args[]) {
Scanner sc = new Scanner(System.in);
System.out.print("Enter The String: ");
String sentence = sc.nextLine();
String word = "";
String wordMostVowel = "";
int abc = 0;
int vowelCount = 0;
char ch;
for (int i = 0; i < sentence.length(); i++) {
ch = sentence.charAt(i);
if (ch != ' ' && i != (sentence.length() - 1)) {
word += ch;
ch = Character.toLowerCase(ch);
if (ch == 'a' || ch == 'e' || ch == 'i' || ch == 'o' || ch == 'u') {
vowelCount++;
}
} else {
if (vowelCount > abc) {
abc = vowelCount;
wordMostVowel = word;
}
word = "";
vowelCount = 0;
}
}
System.out.println("The word with the highest number of vowels is: " + " " + wordMostVowel);
}
}