Prompt:
You have been given a string s, which is supposed to be a sentence. However, someone forgot to put spaces between the different words, and for some reason, they capitalized the first letter of every word. Return the sentence after making the following amendments:
Put a single space between the words. Convert the uppercase letters to lowercase.
Any suggestions on my code?
String amendTheSentence(String s) { StringBuilder modifiedString = new StringBuilder(); char[] sToArray = s.toCharArray(); if (Character.isUpperCase(sToArray[0])) { modifiedString.append(Character.toLowerCase(sToArray[0])); } else { modifiedString.append(sToArray[0]); } for (int i = 1; i < sToArray.length; i++) { char currentChar = sToArray[i]; if (Character.isUpperCase(sToArray[i])) { currentChar = Character.toLowerCase(currentChar); modifiedString.append(" "); } modifiedString.append(currentChar); } return modifiedString.toString(); }