Capitalizing each word in a sentence with loop
public class Main {
public static void main(String[] a) {
String sentence = "this is a test";
String tmp = "";
String[] words = sentence.split(" ");
for (int i = 0; i < words.length; i++) {
tmp += words[i].substring(0, 1).toUpperCase();
tmp += words[i].substring(1).toLowerCase();
tmp += " ";
}
System.out.println(tmp.trim());
}
}
Related examples in the same category