One of the rules for converting English to Pig Latin states
One of the rules for converting English to Pig Latin states: If a word begins with a consonant, move the consonant to the end of the word and add \"ay\". Thus \"dog\" becomes \"ogday,\" and \"crisp\" becomes \"rispcay\". Suppose s is a String containing an English word that begins with a consonant. Which of the following creates the correct corresponding word in Pig Latin? Assume the declarations String ayString = \"ay*; String pigString; pigString = s.substring(0, s,length()) + s.substring(0, 1) + syString; pigString = s.substring(1, s.length()) + s.substring(0, 0) + ayString; pigString = s.substring(0, s.length()-1) + s.substring(0, 1) + ayString; pigString = s.substring(1, s.length()) + s.substring(0, 1) + ayString; pigString = s.substring(1, s.length()) + s.substring(0, 1) + ayString;
Solution
The correct option is option B.
The subString() method which here tooks two parameters the starting index and the ending index of the String.
Here took the example of String s is dog.
Now look subString(1,s.length()) will give string og the string starting from index 1 upto length.
Now next SubString will give d
So upto now the string has become
ogd and now adding ay at the end will give ay, so final string wil become
ogday
