If the English word begins with a consonant, move the consonant to the end of the word and add "ay". The letter Y should be considered a consonant.
If the English word begins with a vowel (A, E, I, O, or U), simply add "way" to the end of the word.
(This is a simplified dialect of Pig Latin, of course.)
Ask the user for a word (one string) and output its Pig Latin translation (one string). You may assume that the input does not contain digits, punctuation, or spaces. The input may be in any combination of uppercase or lowercase. The case of your output does not matter. Use IO.outputStringAnswer() to output.
so far my code is :
public class PigLatin {
public static void main(String[] args)
{
System.out.println("Please enter a phrase that you want me to translate into Pig Latin: ");
String prepig = IO.readString();
char prepig1 = Character.toLowerCase(prepig.charAt(0));
if (prepig1 == "a" || prepig1 == "e" || prepig1 == "i" || prepig1 == "o" || prepig1 == "u")
{
String finalstr = prepig + "way";
System.out.println(finalstr);
}
else
{
String first = prepig.substring(0,1);
String slice = prepig.substring(1,prepig.length());
System.out.println(slice + first + "ay");
}
}
}
However in eclipse, this line
if (prepig1 == "a" || prepig1 == "e" || prepig1 == "i" || prepig1 == "o" || prepig1 == "u")
is in red and it says "Incompatible operand types char and String"
What does this mean and how can I fix it?
Thanks

New Topic/Question
Reply


MultiQuote




|