将一字符串首字母转大写

public class UpperCase {
    public static void main(String[] args) {
        String str = " this is a man";
        String temp = upperCase(str);
        System.out.println(temp);
    }
    public static String upperCase(String str){
        char[] c = str.toCharArray();
        for (int i = 1; i < c.length; i++) {
            if(c[i-1]==' ')
                c[i]=(char) (c[i]-32);
        }
        String s = new String(c);
        return s;
    }
}

 

posted @ 2017-08-09 10:15  如果屈原会编程  阅读(273)  评论(0编辑  收藏  举报