Question in Java Write a program that encodes English-language phrases into pig
ID: 3684724 • Letter: Q
Question
Question in Java
Write a program that encodes English-language phrases into pig Latin. To translate an English word into a pig Latin word, place the first letter of the English word at the end of word and add "ay". For example, "dog" would become "ogday" and cat would become "atcay".
Your program should prompt the user to enter an English sentence and then print the sentence with every word changed to pig Latin. (One way to do this would be to split the sentence into words with the split() method .) For simplicity, there will be no punctuation in the sentences.
Explanation / Answer
import java.io.*;
public class chegg9 {
public static void main(String args[])
{
String input;
try{
BufferedReader br =
new BufferedReader(new InputStreamReader(System.in));
System.out.println("Please type a sentence in english: ");
input=br.readLine();
String words[] = input.split(" ");
int len = words.length;
for(int i=0;i<len;i++)
{
int wid = words[i].length();
char c = words[i].charAt(0);
words[i] = words[i].substring(1,wid)+c+"ay";
System.out.print(words[i]+" ");
}
}catch(IOException io){
io.printStackTrace();
}
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.