Answer:
// here is code in java.
import java.util.*;
// class defintion
class Main
{ //main method of the class
public static void main(String[] args)
{ //scanner object to read input
Scanner sccr = new Scanner( System.in );
System.out.print("Enter your sentence: ");
/* read the sentence and split into the words and store it in the array */
String[] inp_words = sccr.nextLine().split(" ");
System.out.println("words of sentence in pig latin:");
// convert each word into the pig latin
for (String w : inp_words)
{
System.out.print(w.substring(1)+w.substring(0,1)+"ay ");
}
System.out.println();
}
}
Step-by-step explanation:
Create a scanner class object to read input from user.Read the input sentence From user then split it into word and save then into a string array called "inp_words". For each word of input sentence, extract first character and append it in the end of word and then append "ay" to that string.This will change the input sentence into "Pig Latin".
Output:
Enter your sentence: hello world welcome to java
words of sentence in pig latin:
ellohay orldway elcomeway otay avajay