Java Programming Take the problem of PigLatin and apply it to a multi-word input
ID: 663299 • Letter: J
Question
Java Programming
Take the problem of PigLatin and apply it to a multi-word input (also reflecting a name, so the same capitalization rules). As an alternative, follow the capitalization in the words that are passed in. The Character class as the method isUpperCase(char) to do this. Just apply the simple first-letter move rule.
PigLatin:
import java.util.Scanner;
public class PigLatin {
public static void main(String [] args) {
Scanner kb = new Scanner(System.in);
String name, amenay = "";
System.out.print("Enter your first name: ");
name = kb.next();
if (name.length() > 0){
if (name.length() > 1) {
amenay += name.substring(1,2).toUpperCase();
amenay += name.substring(2);
amenay += name.substring(0,1).toLowerCase();
}
else {
amenay = name;
}
amenay += "ay";
}
System.out.println("Hello, " + amenay);
}
}
Explanation / Answer
import java.util.Scanner; public class PigLatin { public static void main(String[] args) { System.out.println("Enter word: "); Scanner scanner = new Scanner(System.in); String findFirstVowel = scan.nextLine(); char v = Character.toLowerCase(findFirstVowel.charAt(0)); if (v == 'a' || v == 'e' || v == 'i' || v == 'o' || v == 'u') { String convertToPigLatin = findFirstVowel + "ay"; System.out.println(convertToPigLatin); } else { String first = findFirstVowel.substring(0,1); String slice = findFirstVowel.substring(1,findFirstVowel.length()); System.out.println(slice + first + "ay"); } } }
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.