Capitalizing each word in a sentence with loop : Char Text « Development Class « Java






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

1.Capitalizing each word in a sentence with recursive function
2.Rules DemoRules Demo
3.Keys DemoKeys Demo
4.Break Iterator DemoBreak Iterator Demo
5.Character DemoCharacter Demo