Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.company;
- import java.util.Scanner;
- public class Main {
- public static void main(String[] args) {
- Scanner in = new Scanner(System.in);
- System.out.print("Enter a sentence: ");
- String sentence = in.nextLine();
- String[] words = sentence.split(" ");
- int maxVowels = 0;
- String wordWithMaxVowels = null;
- for (int x = 0; x < words.length; x++){
- int tempVowels = 0;
- for (int y = 0; y < words[x].length(); y++){
- if ((words[x].charAt(y) + "").matches("[AOEIUaoeiu]"))
- tempVowels++;
- if (tempVowels > maxVowels) {
- maxVowels = tempVowels;
- wordWithMaxVowels = words[x];
- }
- }
- }
- System.out.println("Word with most vowels is: \"" + wordWithMaxVowels + "\" and vowel count in the given word is " + maxVowels);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment