// Program 4: Pig Latin Using Recursion import java.util.*; class Piglatin { String word; String newword; Piglatin() { word = ""; newword = ""; } void input() { Scanner sc = new Scanner(System.in); word = sc.next(); } // Rotate initial consonants recursively. String rotate(String s) { if (s.length() == 0) { return s; } char ch = Character.toUpperCase(s.charAt(0)); if ("AEIOU".indexOf(ch) >= 0) { return s; } return rotate(s.substring(1) + s.charAt(0)); } void convert() { boolean vowel = false; for (int i = 0; i < word.length(); i++) { char ch = Character.toUpperCase(word.charAt(i)); if ("AEIOU".indexOf(ch) >= 0) { vowel = true; } } newword = vowel ? rotate(word) + "ay" : word + "ay"; } void output() { System.out.println(word + " -> " + newword); } public static void main(String[] args) { Piglatin ob = new Piglatin(); ob.input(); ob.convert(); ob.output(); } }