Answer:
String words[]=str.split("\\s");
String capitalizeWord="";
for(String w:words){
String first=w.substring(0,1);
String afterfirst=w.substring(1);
capitalizeWord+=first.toUpperCase()+afterfirst+" ";
}
return capitalizeWord.trim();
Explanation:
Define the word you are trying to capitalize and split it into an array.
String words[]=str.split("\\s");
Create a string for the capital output to be created as
String capitalizeWord="";
Capitalize the word using the "first.toUpperCase()" and "afterfirst" functions
for(String w:words){
String first=w.substring(0,1);
String afterfirst=w.substring(1);
capitalizeWord+=first.toUpperCase()+afterfirst+" ";
}