Skip to content

Instantly share code, notes, and snippets.

@cmh114933
Created May 10, 2019 08:06
Show Gist options
  • Save cmh114933/7ab379739b7ad5e027de8d901ed13eae to your computer and use it in GitHub Desktop.
Save cmh114933/7ab379739b7ad5e027de8d901ed13eae to your computer and use it in GitHub Desktop.
pig latin part 1
import java.util.Arrays;
/**
* PigLatin
*/
public class PigLatin {
static String convert(String word){
// Your Code
Character[] vowels = {'a','e','i','o','u'};
char[] wordChars = word.toCharArray();
int firstVowelIndex = -1;
for(int i = 0; i < wordChars.length; i++){
Character currentChar = wordChars[i];
boolean isVowel = Arrays.asList(vowels).contains(currentChar);
System.out.println(currentChar + " : " + isVowel);
if(isVowel){
firstVowelIndex = i;
break;
}
}
if(firstVowelIndex == 0){
return word;
}else if(firstVowelIndex > 0){
} else {
return word + "ay";
}
}
public static void main(String[] args){
System.out.println(convert("art").equals("art"));
System.out.println(convert("vowel").equals("owelvay"));
System.out.println(convert("nginx").equals("inxngay"));
System.out.println(convert("hello").equals("ellohay"));
System.out.println(convert("Dr").equals("Dray"));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment