/** * Returns the result of converting s to \"Pig Latin\". Convert a string s to
ID: 668217 • Letter: #
Question
/**
* Returns the result of converting s to "Pig Latin". Convert a string s to Pig Latin by using the following rules:
*
* (1) If s contains no vowels, do nothing to it.
*
* (2) Otherwise, if s starts with a vowel, append "way" to the end.
*
* (3) Otherwise, move everything up to (but not including) the first vowel to the end and add "ay".
*
* For example, "hello" converts to "ellohay", "small" converts to "allsmay", "eat" converts to "eatway", and "nth"
* converts to "nth".
*
* IMPLEMENTATION NOTE: This will require a three-way conditional that extracts pieces of Strings and recombines
* them into new Strings. For full credit (and an easier implementation), use the firstVowelIndex method provided
* above in your method's implementation. You will also find the methods s.substring() and s.charAt() (where s is a
* String), as well as the + operator that concatenates Strings, very useful.
*/
public static String toPigLatin (String s)
{
return "";
}
Explanation / Answer
Have in mind that you didn't include the firstVowelIndex method provided, which is required for full credit. However, I implemented one assuming it would be static, however, if the one the problem provides is static, you can remove my implementation from the code, just the -public static Integer firstVowelIndex (String s)- block but, if it is not static, then you would have to change inside toPigLatin method, where it says firstVowelIndex(s) to s.firstVowelIndex() public class Main { public static void main(String[] args){ String test="nth"; toPigLatin(test); } public static String toPigLatin (String s) { String back=""; String ending=""; String part=""; Boolean flag=false; for (int i=0;iRelated Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.