logo CodeStepByStep logo

pigLatin

Language/Type: Java file input
Related Links:
Author: Nick Troccoli (on 2017/04/25)

Write a method named pigLatin that accepts as a parameter a Scanner representing an input file. Your method should, preserving line breaks, print out the input file's text in a simplified version of Pig Latin, a silly English variant where the first letter of each word is moved to the end. The rules for translating a word to Pig Latin are as follows:

  • If the word starts with a vowel (aeiou), simply append "yay". For example, "elephant" becomes "elephantyay".
  • If the word starts with a consonant, move the consonant to the end, and append "ay". For example, "welcome" becomes "elcomeway".

As an overall example, if the input file lincoln.txt contains the following text:

four score and
seven years ago our
fathers brought forth on this continent a new nation

We might call your method as follows:

Scanner input = new Scanner(new File("lincoln.txt"));
pigLatin(input);

The above call should produce the following output:

ourfay coresay andyay
evensay earsyay agoyay ouryay
athersfay roughtbay orthfay onyay histay ontinentcay ayay ewnay ationnay
Type your Java solution code here:


This is a method exercise. Write a Java method as described. Do not write a complete program or class; just the method(s) above.

You must log in before you can solve this problem.

Log In

Need help?

If you do not understand how to solve an exercise or why your solution doesn't work, please contact your TA or instructor.
If something seems wrong with the site (errors, slow performance, incorrect tests, etc.), please

Is there a problem? Contact a site administrator.

©, all rights reserved.