reAay ouyay aay hizway ithway igPay atinLay Translated Are y
Solution
solution
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?

