Basically, (dog)(cat)(mouse) needs to be (dog) (cat) (mouse).
My attempted code:
StringBuilder sb = new StringBuilder("(dog)(cat)(mouse)");
for (int i = 0; i < sb.length(); i ++)
{
if (sb.charAt(i) == ')')
{
sb.insert(i, ' ');
}
}
String result = sb.toString();
But I'm getting some sort of "Java heap space" error
sb.insert(i, ' ');insert the space?), it adds a space BEFORE it, so on the next iteration, it will find another)(creating something like" )"). You could see this if you add aSystem.out.printlnafter each iteration)but you have the idea right.