Convert to Title Case

Convert a sentence to title case (first letter of each word uppercase).

JavaBeginner
Java
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        System.out.print("Enter a sentence: ");
        String s = sc.nextLine().toLowerCase();

        String[] words = s.trim().split("\\s+");
        StringBuilder sb = new StringBuilder();
        for (String w : words) {
            if (w.isEmpty()) continue;
            sb.append(Character.toUpperCase(w.charAt(0)))
              .append(w.substring(1))
              .append(" ");
        }
        System.out.println("Title case: " + sb.toString().trim());
        sc.close();
    }
}

Output

Enter a sentence: java is awesome
Title case: Java Is Awesome

We lowercase the sentence, then uppercase the first character of each word.