Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class PigLatin {
- public static void main(String[] args) {
- String phrase = "The rain in Spain stays mainly on the plain but the ants in France stay mainly on the plants", completed = " ";
- String[] words = phrase.split(" ");
- for (int i = 0; i < words.length; i++) {
- words[i] = words[i].toLowerCase();
- completed += createPigLatin(words[i]) + " ";
- }
- // test = test.toLowerCase();
- // System.out.println(createPigLatin(test));
- System.out.println("The original phrase: " + phrase);
- System.out.println("Pig Latin: " + completed);
- }
- public static String createPigLatin(String word) {
- String result, firstPart = "", secondPart = "";
- char charCheck = word.charAt(0);
- if (charCheck == 'a' || charCheck == 'e' || charCheck == 'i'
- || charCheck == 'o' || charCheck == 'u') {
- result = word + "-yay";
- } else {
- for (int i = 0; charCheck != 'a' && charCheck != 'e'
- && charCheck != 'i' && charCheck != 'o' && charCheck != 'u'; i++) {
- firstPart = word.substring(0, i);
- secondPart = word.substring(i);
- charCheck = word.charAt(i);
- }
- result = secondPart + "-" + firstPart + "ay";
- }
- return result;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement