My Pig Latin translator translates words only. I need to make the translator translate phrases as well as words. I tried a couple of times by trying to add a for() loop but it didn't work.
Here is the code: import java.util.Scanner;
public static void main(String[] args) {
System.out.println("WHAT DO YOU WANT IM TRYING TO SLEEP!!!!\n"
+ "JUST ENTER WHAT YOU WANT TRANSLATED!!!!! ");
Scanner keyboard = new Scanner( System.in );
String phrase = keyboard.nextLine();
String[] word = phrase.split(" ");
for(int i = 0; i < word.length; i++ )
{
char firstLetter = (word[i].charAt(0));
if (firstLetter == 'a' || firstLetter == 'e' || firstLetter == 'i' ||
firstLetter == 'o' || firstLetter == 'u')
{
String vowel = word[i] +"way";
System.out.print(vowel);
}
else
{
String start = word[i].substring(0,1);
String end = word[i].substring(1,phrase.length());
System.out.print(end + start + "ay");
} }
System.out.println("\n"
+ "NOW LEAVE!!!!!");
}}
Aucun commentaire:
Enregistrer un commentaire