将每一个单词的首字母都转成大写的

来源:互联网 发布:优先级调度算法流程图 编辑:程序博客网 时间:2024/05/17 08:57

 

/**
 * 题目要求 
 *   将每一个单词的首字母都转成大写的
 * @author Administrator
 *
 */
public class Homework {
 public static void main(String[] args) {

  String story = "Mr. and Mrs. Dursley, of number four, Privet Drive, were proud to say that they were perfectly normal, thank you very much. They were the last people you'd expect to be involved in anything strange or mysterious, because they just didn't hold with such nonsense.Mr. Dursley was the director of a firm called Grunnings, which made drills. He was a big, beefy man with hardly any neck, although he did have a very large mustache. Mrs. Dursley was thin and blonde and had nearly twice the usual amount of neck, which came in very useful as she spent so much of her time craning over garden fences, spying on the neighbors. The Dursleys had a small son called Dudley and in their opinion there was no finer boy anywhere.";
 
  String sto[]=story.split(" ");
  StringBuilder builder = new StringBuilder();
  for(int i=0;i<sto.length;i++){
   sto[i]=(sto[i].substring(0,1)).toUpperCase().concat(sto[i].substring(1,sto[i].length()));
   builder.append(sto[i].concat(" "));
   }
 
  System.out.println(builder);
  
 }
}

0 0