So i've got a for loop that's reversing every other word in a string. I can't determine which condition is causing this. I've spent a good amount of time staring at this and the API, to no avail. Anyone have any idea why it's not working?
String newMessage;
StringBuilder stringBuilder = new StringBuilder();
newMessage = messageToEncrypt.replaceAll("[^0-9a-zA-z\\s]",""); //check for a non-word character
String[] words = newMessage.split("\\s"); // Array to split the words into each index
for (int i = 0; i < words.length; i++)
{
stringBuilder.append(words[(words.length-1)-i]);
stringBuilder.reverse();
//stringBuilder.append(words[words.length-1]);
stringBuilder.append(" ");
}
newMessage = stringBuilder.toString();
return newMessage;