Java Reference
In-Depth Information
LISTING 7.13
continued
public class PigLatin
{
//-----------------------------------------------------------------
// Reads sentences and translates them into Pig Latin.
//-----------------------------------------------------------------
public static void main (String[] args)
{
String sentence, result, another;
Scanner scan = new Scanner (System.in);
do
{
System.out.println ();
System.out.println ("Enter a sentence (no punctuation):");
sentence = scan.nextLine();
System.out.println ();
result = PigLatinTranslator.translate (sentence);
System.out.println ("That sentence in Pig Latin is:");
System.out.println (result);
System.out.println ();
System.out.print ("Translate another sentence (y/n)? ");
another = scan.nextLine();
}
while (another.equalsIgnoreCase("y"));
}
}
OUTPUT
Enter a sentence (no punctuation):
Do you speak Pig Latin
That sentence in Pig Latin is:
oday ouyay eakspay igpay atinlay
Translate another sentence (y/n)? y
Enter a sentence (no punctuation):
Play it again Sam
That sentence in Pig Latin is:
ayplay ityay againyay amsay
Translate another sentence (y/n)? n
Search WWH ::




Custom Search