Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 15th, 2012  |  syntax: None  |  size: 1.54 KB  |  hits: 12  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. piglatin translator java
  2. public static void pigLatin(String s) {
  3.         char[] array = s.trim().toCharArray();
  4.         if(isVowel(s.charAt(0)) && !Character.toString(s.charAt(0)).equalsIgnoreCase("y")){
  5.             System.out.println(s+"way");
  6.         }else {
  7.             int i = 0;
  8.             String toReturn = "";
  9.             do {
  10.                 toReturn += array[i];
  11.                 i++;
  12.             }while(!isVowel(s.charAt(i)) && !Character.toString(array[i]).equalsIgnoreCase("y"));
  13.             System.out.println(s.substring(i)+toReturn+"ay");
  14.         }
  15.     }
  16.  
  17.     public static boolean isVowel(char c) {
  18.         char[] vowels = new char[] {'a','e','i','o','u','y'};
  19.         for(int i = 0;i<vowels.length;i++) {
  20.             if(Character.toString(vowels[i]).equalsIgnoreCase(Character.toString(c))) {
  21.                 return true;
  22.             }
  23.         }
  24.         return false;
  25.     }
  26.        
  27. while( (!isVowel(s.charAt(i)) || isQU(s, i)) && !Character.toString(array[i]).equalsIgnoreCase("y"))
  28.        
  29. public static String pigLatin(String a){
  30.     a=a.toLowerCase();
  31.     String [] x=a.split(" ");
  32.     int vowl=0;
  33.     String c="";
  34.     String d="";
  35.     String trans="";
  36.     for(int i=0; i<x.length; i++){
  37.        for(int j = 0;j<x[i].length();j++){
  38.            if(x[i].charAt(j)=='a'||x[i].charAt(j)=='e'||x[i].charAt(j)=='i'||x[i].charAt(j)=='o'||x[i].charAt(j)=='u'){
  39.                vowl=j;
  40.                j=x[i].length();
  41.             }
  42.         }
  43.        c=x[i].substring(0,vowl);
  44.        d=x[i].substring(vowl,x[i].length());
  45.        trans+= d+c+"ay ";
  46.     }
  47.     return trans;
  48. }