Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a program that encodes English-language phrases into pig Latin. To transla

ID: 3839941 • Letter: W

Question

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 tis would be to split the sentence into words with the split() method.) For simplicity, there will be no punctuation in the sentences.

Run like:

Enter a string to be translated: the fox jumps over the lazy dog

hetax oxfay umpsjay veroay hetay azylay ogday

Explanation / Answer

PiLatinWithMultipleWords.java


import java.util.Scanner;

public class PiLatinWithMultipleWords {

   public static void main(String[] args) {
       Scanner scan = new Scanner(System.in);
       System.out.print("Enter a string to be translated: ");
       String s = scan.nextLine();
       String words[] = s.split("\s+");
       for(String word: words){
           System.out.print(pigLatin(word)+" ");
       }
       System.out.println();
   }

   public static String pigLatin (String s){
  
   s = s.toLowerCase();
       s = s.substring(1,s.length())+ s.charAt(0) + "ay";
   return s;
   }
  
}

Output

Enter a string to be translated: the fox jumps over the lazy dog
hetay oxfay umpsjay veroay hetay azylay ogday

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote