/*
* Purpose: To convert an English sentence into Pig Latin.
*/
import java.util.*;
public class PigLatin {
public static void main(String[]args){
Scanner in = new Scanner(System.in);
String phrase;
System.out.print("English: ");
phrase = in.nextLine();
System.out.print("\nTranslation: " + phraseToPig(phrase));
}
public static boolean isCapitalized(String word){ //returns True if the word is capitalized
String firstLetter = word.substring(0,1), temp;
temp = firstLetter.toUpperCase();
return(firstLetter == temp);
}
public static String lowerCase(String word){ //converts String to Lower Case
return(word.toLowerCase());
}
public static String upperCase(String word){ //converts String to Upper Case
String firstLetter;
firstLetter = word.substring(0,1);
return(firstLetter.toUpperCase() + word.substring(1, word.length()));
}
public static String wordToPig(String english){ //converts english word to Pig Latin
String word = english;
int isCap = 0;
int position = hasAVowel(word);
if(isCapitalized(word)){
word = lowerCase(word);
isCap = 1;
}
if(position == word.length())
word += "ay";
else if(position == 0)
word += "yay";
else
word = word.substring(position, word.length()) + word.substring(0, position) + "ay";
if(isCap == 1)
word = upperCase(word);
return(word);
}
public static String phraseToPig(String phrase){ //converts english sentence to Pig Latin}
StringTokenizer token = new StringTokenizer(phrase);
String english, pigPhrase = "";
while(token.hasMoreTokens()){
english = token.nextToken();
pigPhrase += wordToPig(english) + " ";
}
return(pigPhrase);
}
public static int hasAVowel(String word){ //returns index of first vowel (all 10) (return -1 if no vowels in word)
int place = 0, lowest = word.length();
String vowel[] = {"a", "e", "i", "o", "u", "A", "E", "I", "O", "U"};
for(int i = 0; i place = word.indexOf(vowel[i]);
if(place < lowest && place != -1)
lowest = place;
}
return(lowest);
}
}
* Purpose: To convert an English sentence into Pig Latin.
*/
import java.util.*;
public class PigLatin {
public static void main(String[]args){
Scanner in = new Scanner(System.in);
String phrase;
System.out.print("English: ");
phrase = in.nextLine();
System.out.print("\nTranslation: " + phraseToPig(phrase));
}
public static boolean isCapitalized(String word){ //returns True if the word is capitalized
String firstLetter = word.substring(0,1), temp;
temp = firstLetter.toUpperCase();
return(firstLetter == temp);
}
public static String lowerCase(String word){ //converts String to Lower Case
return(word.toLowerCase());
}
public static String upperCase(String word){ //converts String to Upper Case
String firstLetter;
firstLetter = word.substring(0,1);
return(firstLetter.toUpperCase() + word.substring(1, word.length()));
}
public static String wordToPig(String english){ //converts english word to Pig Latin
String word = english;
int isCap = 0;
int position = hasAVowel(word);
if(isCapitalized(word)){
word = lowerCase(word);
isCap = 1;
}
if(position == word.length())
word += "ay";
else if(position == 0)
word += "yay";
else
word = word.substring(position, word.length()) + word.substring(0, position) + "ay";
if(isCap == 1)
word = upperCase(word);
return(word);
}
public static String phraseToPig(String phrase){ //converts english sentence to Pig Latin}
StringTokenizer token = new StringTokenizer(phrase);
String english, pigPhrase = "";
while(token.hasMoreTokens()){
english = token.nextToken();
pigPhrase += wordToPig(english) + " ";
}
return(pigPhrase);
}
public static int hasAVowel(String word){ //returns index of first vowel (all 10) (return -1 if no vowels in word)
int place = 0, lowest = word.length();
String vowel[] = {"a", "e", "i", "o", "u", "A", "E", "I", "O", "U"};
for(int i = 0; i place = word.indexOf(vowel[i]);
if(place < lowest && place != -1)
lowest = place;
}
return(lowest);
}
}
Published by Chris Chen
Chris is currently attending the University of California, Berkeley seeking an undergraduate's degree in Electrical Engineering Computer Science. He enjoys playing basketball, practicing kendo, hanging out w... View profile
Terminal Length and the Role of Genetics in Black Hair CareImproving the length and condition of black hair obviously does not happen by accident, but where do genetics and terminal length come into play?
- THE BEST FOUR-LETTER WORD EVERThe word "free" is the best four-letter word ever invented for marketing. How can you incorporate free samples, articles, consultations, etc. into your marketing?
- What Does The Word Psychic Really Mean?Do you know what the word psychic means? Do you think that most people feel that a psychic is someone who worships the devil? What is the truth about a psychic?
Paul Mooney on Michael Richards: He Cured Me of Using the N-WordComedian Paul Mooney vows to never use the N-word again during Jesse Jackson press conference
- JavaScript String Regular Expression Patterns
- Introduction to JavaScript String Regular Expressions
- Commonly Used Latin Words and Phrases in Modern English
- Your First Java Program
- Malcolm Brown, M.D. - Ghetto Doctor
- The "N" Word and 20 Other Offensive Words
- Who is the Word of God?



