Returns the reversed vowel of a string. The other words remain unchanged.
Train of Thought: Use ArrayList to store vowels (because there is a contains method), and record the number of vowels and put them into the stack (reverse similar to stack first and then out), which uses string and char array conversion.
Import java. util. arrayList; import java. util. list; import java. util. imports; import java. util. stack; public class reverseWords {public static String reverseVowels (String s) {Stack <String> replace = new Stack <String> (); // use the stack to output the List <Character> contain = new ArrayList <Character> (); // store the vowel int count = 0; // The number of vowel letters contain. add ('A'); contain. add ('E'); contain. add ('I'); contain. add ('O'); contain. add ('U'); contain. add ('A'); contain. add ('E'); contain. add ('I'); contain. add ('O'); contain. add ('U'); char [] ch = s. toCharArray (); for (int I = 0; I <s. length (); I ++) {if (contain. contains (ch [I]) count ++;} if (count <2) return s; // The number of vowels smaller than two does not need to be reversed int [] num = new int [count]; // record the vowel position int j =-1; for (int I = 0; I <ch. length; I ++) {if (contain. contains (ch [I]) {num [++ j] = I; replace. push (String. valueOf (ch [I]); // stack feed} for (int I = 0; I <count; I ++) {ch [num [I] = replace. pop (). charAt (0);} return String. valueOf (ch); // toString ()} public static void main (string [] args) cannot be used to convert a char array to a String) {// TODO Auto-generated method stub initialize partition = new partition (System. in); while (partial. hasNext () {String str = success. next (); System. out. println (reverseVowels (str ));}}}