// Program 70: Count Words Beginning and Ending with a Vowel import java.util.*; class VowelBoundedWords { static boolean vowel(char c) { return "AEIOU".indexOf(c) >= 0; } public static void main(String[] args) { Scanner sc = new Scanner(System.in); String s = sc.nextLine().trim(); if (!s.matches("[A-Z]+( [A-Z]+)*[.?!]")) { System.out.println("INVALID INPUT"); return; } String[] words = s.substring(0, s.length() - 1).split(" "); ArrayList yes = new ArrayList<>(), no = new ArrayList<>(); for (String w : words) { if (vowel(w.charAt(0)) && vowel(w.charAt(w.length() - 1))) { yes.add(w); } else { no.add(w); } } System.out.println("NUMBER OF WORDS BEGINNING AND ENDING WITH A VOWEL = " + yes.size()); yes.addAll(no); System.out.println(String.join(" ", yes)); } }