Chapter 9 Text Processing and More about wrapper Classes 15. Pig Latin Write a p
ID: 3822292 • Letter: C
Question
Chapter 9 Text Processing and More about wrapper Classes 15. Pig Latin Write a program that reads a sentence as input and converts each word to "Pig Latin". In one version of Pig Latin, you convert a word by removing the first letter, that letter at the end of the word, and then appending "ay" to the word. Here is an example: I SLEPT MOST OF THE NIGHT English: LAY LEPTSAY OSTMAY FOAY HETAY IGHTNAY Pig Latin: 16. Morse Code Converter digit, and various Morse code is a code where each letter of the English alphabet, each Table 9-14 shows punctuation characters are represented by a series of dots and dashes. part of the code. Write a program that asks the user to enter a string, and then converts that string to Morse code. Use hyphens for dashes and periods for dots. able 9-14 Morse code Character Code Character Code Character Code Character Code space commaExplanation / Answer
15.
import java.util.Scanner;
public class PigLatin {
public static String convertToPigLatin(String sentence)
{
StringBuilder sb = new StringBuilder();
String[] words = sentence.split("\s+");
for(String word: words)
{
sb.append( word.substring(1) + word.charAt(0) + "AY ");
}
return sb.toString();
}
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
System.out.print("English: ");
String sentence = sc.nextLine();
String pigLatinSentence = convertToPigLatin(sentence);
System.out.print("Pig Latin: " + pigLatinSentence + " ");
sc.close();
}
}