reAay ouyay aay hizway ithway igPay atin?Lay? (Translated: "Are you a whiz with Pig Latin?") Write a program that converts an English phrase into a pseudo-Pig Latin phrase (that is Pig Latin that doesn’t follow all the Pig Latin syntax rules). Use predefined methods of the Array and string classes to do the work. For simplicity in your conversion, place the first letter as the last character in the word and prefix the characters "ay" onto the end. For example, the word "example" would become "xam-pleeay," and "method" would become "ethodmay." Allow the user to input the English phrase. After converting it, display the new Pig Latin phrase.

Respuesta :

Answer:

Check the explanation

Explanation:

package com.prt.test;

package com.prt.test;

  import java.util.Arrays;

  import java.util.Scanner;

  public class StringEncryption {

      public static void main(String[] args)

      {

  try{

          String concatedString1="";//testing();

          StringBuffer encryptedString=new StringBuffer();

Scanner scanner = new Scanner(System.in);

         

          System.out.println("enter the string ");

         

          String userInput = scanner.nextLine();// to read the string

         

          String[] words=userInput.split("\\s");//to split the words if user enter the string with period

         

          for(String word:words)

          {

              int numberOfSpacesadd=1;

              String subs=word.substring(0, 1);//to split the first letter

              String s1=word.substring(1);//to split the after the first letter

              String concatedString=s1+subs;

              concatedString1=concatedString+"ay";//to add the adding phrase

              String addSpace = String.format("%"+ numberOfSpacesadd +"s", " ");//for adding the space after the word

                 

              encryptedString.append(concatedString1+addSpace);

             

          }

         

System.out.println(encryptedString.toString().trim()+"?");

  }catch(Exception e)

  {

      System.out.println(" try another time");

  }  

      }

  }

 

Output :

enter the string

Are You a Whiz with Pig Latin?

reAay ouYay aay hizWay ithway igPay atin?Lay?