I want to write a program that will insert the word "like" in between the spaces of each word in a sentence. What I have attempted so far:
public String teenTalk(String sentence)
{
for (int i = 0; i < sentence.length(); i++)
{
char sentC = sentence.charAt(i);
String sentS = Character.toString(sentence);
if (sentS.equals(" "))
{
sentence = sentence.replaceAll(" ", " like ");
}
return sentence;
}
Please excuse any inefficiencies as I am still relatively new to programming in general. I recently got intensely into Strings and Chars, but I still lack much knowledge in how they work, so I'm guessing my code has illogical errors. I'd be thankful if someone could point them out.
I did find another forum on this (Write method that puts the word "like" in between each of the words in the original sentence) asking for the same thing. However, the website that I have to turn this assignment into has an IDE that is extremely limited and will not compile tokens or lists. I have yet to test .replace and .replaceAll but I will place an update after I get my attempted code fixed. Thanks for any help inadvance