Question: Write a program that reads a sentence as input (from keyboard) and converts each word to pig Latin. In this version of Pig Latin, you

Write a program that reads a sentence as input (from keyboard) and converts each word to pig Latin. In this version of Pig Latin, you convert a word by removing the first letter, placing that letter at the end of the word and then appending ay to the word (all uppercase). For example, if the input is I am Fred then the output would be IAY MAAY REDFAY.

This is what I have:

public class pigLatin{ public static void main(String[] args){ Scanner sw = new Scanner(System.in); System.out.println("Type in a sentence :: "); String Input = sw.nextLine(); StringBuilder str = new StringBuilder(Input); String[] words = Input.split(" "); for(String w: words){ char f = str.charAt(0); str.deleteCharAt(0); System.out.print(str.append(f+"ay")); } } }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!