(Coderbyte) Letter Capitalize - Solução

Have the function LetterCapitalize(str) take the str parameter being passed and capitalize the first letter of each word. Words will be separated by only one space.

Solução:

import java.util.*;
import java.io.*;

class Function { 
  String LetterCapitalize(String str) {
    String result = "";
   
    StringTokenizer palavras = new StringTokenizer(str); 
    while(palavras.hasMoreTokens()) {       
      String palavra = palavras.nextToken();
      result += palavra.substring(0,1).toUpperCase();
      result += palavra.substring(1,palavra.length());
      result += " ";
    } 

    return result.substring(0,result.length()-1);
   
  }
 
  public static void main (String[] args) { 
    // keep this function call here    
    Scanner  s = new Scanner(System.in);
    Function c = new Function();
    System.out.print(c.LetterCapitalize(s.nextLine()));
  }  
 
}           

Comments

Popular posts from this blog

(Coderbyte) Dash Insert II - Solução

(Coderbyte) Run Length - Solução

(Coderbyte) Counting Minutes I - Solução