package com.rui.first;
public class demo {
public static void main(String[] args) {
String strb="you and me what cpp2005program";
System.out.println(StrLogin(strb));
}
public static String StrLogin(String str){
char [] ch=str.toCharArray();
StringBuilder strbuf=new StringBuilder(str);
if ( (int)ch[0]>97 ) {
ch[0]=(char)((int)ch[0]-32);
}
for (int i = 0; i < ch.length; i++) {
if (ch[i]==' ') {
if (ch[i+1] ==' ') {
System.out.println(strbuf.deleteCharAt(i+1).toString());
StrLogin(strbuf.deleteCharAt(i+1).toString());
}else {
ch[i+1]=(char)((int)ch[i+1]-32);
}
}
}
return String.copyValueOf(ch);
}
}
把首字母换成大写,删除多余的空格.....可结果是:
you and me what cpp2005program
you and me what cp2005program
You And Me What Cpp2005program