The method below takes a String parameter called str. Complete the method so that it returns a
Fantastic news! We've Found the answer you've been seeking!
Question:
The method below takes a String parameter called str. Complete the method so that it returns a new string where each each character in the original string has been repeated 3 times. For example if the string given is "cat", the string returned should be "cccaaattt". What needs to be added to the code below
public String tripleLetters(String str)
{
String newString = "";
// Use a for loop to traverse the characters in the string
for (int i = 0; // Finish this for loop )
{
char letter = str.charAt(i);
// perform the action in the body of the loop 3 times
for (int j = 0; // Finish this for loop )
{
newString = newString + letter;
}
}
return newString;
}
Related Book For
Posted Date: