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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started