Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private static String separate(String x) //separates the string into separate words
- {
- if (x.length() == 0){
- return "";
- }else{
- //return pigLatin(x.substring(0, x.indexOf(" "))) + " " + separate(x.substring(x.indexOf(" ") + 1, x.length()));
- return separate(x.substring(0, x.indexOf(' ')));
- }
- }
- /**
- * Receives a String, converts the String to Pig Latin,
- * and returns the new Pig Latinated word.
- */
- public static String pigLatin(String x) //translates the string into piglatin
- {
- if (x.indexOf('a') == -1 && x.indexOf('e') == -1 && x.indexOf('i') == -1 && x.indexOf('o') == -1 && x.indexOf('u') == -1
- && x.indexOf('A') == -1 && x.indexOf('E') == -1 && x.indexOf('I') == -1 && x.indexOf('O') == -1 && x.indexOf('U') == -1){
- return x + "ay";
- }else if(x.charAt(0) == 'a' || x.charAt(0) == 'e' || x.charAt(0) == 'i' || x.charAt(0) == 'o' || x.charAt(0) == 'u'
- || x.charAt(0) == 'A' || x.charAt(0) == 'E' || x.charAt(0) == 'I' || x.charAt(0) == 'O' || x.charAt(0) == 'U'){
- return x + "yay";
- }else{
- return end(x) + start(x) + "ay";
- }
- }
- private static String end(String x) //the end part of the piglatin translation
- {
- if (x.charAt(0) == 'a' || x.charAt(0) == 'e' || x.charAt(0) == 'i' ||
- x.charAt(0) == 'o' || x.charAt(0) == 'u'){
- return x;
- }else{
- return end(x.substring(1));
- }
- }
- private static String start(String x) //the start part of the piglatin translation
- {
- int n = 100;
- if (x.indexOf('a') != -1 && x.indexOf('a') < n){
- n = x.indexOf('a');
- }
- if (x.indexOf('e') != -1 && x.indexOf('e') < n){
- n = x.indexOf('e');
- }
- if (x.indexOf('i') != -1 && x.indexOf('i') < n){
- n = x.indexOf('i');
- }
- if (x.indexOf('o') != -1 && x.indexOf('o') < n){
- n = x.indexOf('o');
- }
- if (x.indexOf('u') != -1 && x.indexOf('u') < n){
- n = x.indexOf('u');
- }
- if (x.indexOf('A') != -1 && x.indexOf('A') < n){
- n = x.indexOf('A');
- }
- if (x.indexOf('E') != -1 && x.indexOf('E') < n){
- n = x.indexOf('E');
- }
- if (x.indexOf('I') != -1 && x.indexOf('I') < n){
- n = x.indexOf('I');
- }
- if (x.indexOf('O') != -1 && x.indexOf('O') < n){
- n = x.indexOf('O');
- }
- if (x.indexOf('U') != -1 && x.indexOf('U') < n){
- n = x.indexOf('U');
- }
- return x.substring(0,n);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement