Advertisement
Dakpluto

PigLatin.java

Oct 30th, 2014
188
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.16 KB | None | 0 0
  1. public class PigLatin {
  2.     public static void main(String[] args) {
  3.         String phrase = "The rain in Spain stays mainly on the plain but the ants in France stay mainly on the plants", completed = " ";
  4.         String[] words = phrase.split(" ");
  5.         for (int i = 0; i < words.length; i++) {
  6.             words[i] = words[i].toLowerCase();
  7.             completed += createPigLatin(words[i]) + " ";
  8.         }
  9.         // test = test.toLowerCase();
  10.         // System.out.println(createPigLatin(test));
  11.         System.out.println("The original phrase: " + phrase);
  12.         System.out.println("Pig Latin: " + completed);
  13.     }
  14.  
  15.     public static String createPigLatin(String word) {
  16.         String result, firstPart = "", secondPart = "";
  17.         char charCheck = word.charAt(0);
  18.  
  19.         if (charCheck == 'a' || charCheck == 'e' || charCheck == 'i'
  20.                 || charCheck == 'o' || charCheck == 'u') {
  21.             result = word + "-yay";
  22.         } else {
  23.             for (int i = 0; charCheck != 'a' && charCheck != 'e'
  24.                     && charCheck != 'i' && charCheck != 'o' && charCheck != 'u'; i++) {
  25.                 firstPart = word.substring(0, i);
  26.                 secondPart = word.substring(i);
  27.                 charCheck = word.charAt(i);
  28.             }
  29.             result = secondPart + "-" + firstPart + "ay";
  30.         }
  31.  
  32.         return result;
  33.     }
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement