fork(8) download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone
  9. {
  10. public static void main (String[] args) throws java.lang.Exception
  11. {
  12. String str = "java cSharp pYthOn";
  13. System.out.println(toTitledCase(str));
  14. }
  15.  
  16. public static String toTitledCase(String str){
  17.  
  18. String[] words = str.split("\\s");
  19. StringBuilder sb = new StringBuilder();
  20.  
  21. for(int i = 0; i < words.length; i++){
  22. sb.append(words[i].substring(0, 1).toUpperCase() + words[i].substring(1).toLowerCase());
  23. sb.append(" ");
  24. }
  25.  
  26. return sb.toString();
  27. }
  28.  
  29. }
Success #stdin #stdout 0.06s 711168KB
stdin
Standard input is empty
stdout
Java Csharp Python