Access Millions of academic & study documents

A method String toPigLatin() that returns a String containing the

Content type
User Generated
Showing Page:
1/2
A method String toPigLatin() that returns a String
containing the \'pig latin\' version of the instance variable.
The rules for translating a word to pig latin are: If the word
begins with a consonant, take the first letter of the word
and move it to the end of the word, followed by \'ay\' If the
word begins with a vowel, add \'way\' to the word. Hint: the
method beginVowel() makes this easier. PIG LATIN IS
FUN becomes IGPAY ATINLAY ISWAY UNFAY in pig latin.
Solution
public class HelloWorld{
public static String toPigLatin(String sentence)
{
String word[]=sentence.split(\" \");
String temp=\"\";
for(int i=0;i<word.length;i++)
{
if(beginVowel(word[i].charAt(0)))
temp+=word[i]+\"WAY\";
else
temp+=word[i].substring(1,word[i].length())+word[i].charAt(
0)+\"AY\";

Sign up to view the full document!

lock_open Sign Up
Showing Page:
2/2

Sign up to view the full document!

lock_open Sign Up
Unformatted Attachment Preview
A method String toPigLatin() that returns a String containing the \'pig latin\' version of the instance variable. The rules for translating a word to pig latin are: If the word begins with a consonant, take the first letter of the word and move it to the end of the word, followed by \'ay\' If the word begins with a vowel, add \'way\' to the word. Hint: the method beginVowel() makes this easier. PIG LATIN IS FUN becomes IGPAY ATINLAY ISWAY UNFAY in pig latin. Solution public class HelloWorld{ public static String toPigLatin(String sentence) { String word[]=sentence.split(\" \"); String temp=\ ...
Purchase document to see full attachment
User generated content is uploaded by users for the purposes of learning and should be used following Studypool's honor code & terms of service.
Studypool
4.7
Indeed
4.5
Sitejabber
4.4