Guest User

Untitled

a guest
May 27th, 2017
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.95 KB | None | 0 0
  1. package com.company;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class Main {
  6.     public static void main(String[] args) {
  7.  
  8.         Scanner in = new Scanner(System.in);
  9.         System.out.print("Enter a sentence: ");
  10.         String sentence = in.nextLine();
  11.         String[] words = sentence.split(" ");
  12.  
  13.         int maxVowels = 0;
  14.         String wordWithMaxVowels = null;
  15.  
  16.         for (int x = 0; x < words.length; x++){
  17.             int tempVowels = 0;
  18.             for (int y = 0; y < words[x].length(); y++){
  19.                 if ((words[x].charAt(y) + "").matches("[AOEIUaoeiu]"))
  20.                     tempVowels++;
  21.  
  22.                 if (tempVowels > maxVowels) {
  23.                     maxVowels = tempVowels;
  24.                     wordWithMaxVowels = words[x];
  25.                 }
  26.             }
  27.         }
  28.  
  29.         System.out.println("Word with most vowels is: \"" + wordWithMaxVowels + "\" and vowel count in the given word is " + maxVowels);
  30.  
  31.     }
  32. }
Advertisement
Add Comment
Please, Sign In to add comment