输入单词将首字母大写

输入单词将首字母大写
输入单词将首字母大写

    public static void main(String[] args) throws IOException {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        String s = reader.readLine();

        StringBuffer sb = new StringBuffer();
        char[] chars = s.toCharArray();
        for (int i = 0; i < chars.length; i++) {
            char c = (i == 0 || chars[i - 1] == ' ') ? Character.toUpperCase(chars[i]) : chars[i];
            sb.append(c);
        }
        System.out.println(sb);
    }
}

上一篇:剑指58-II 左旋转字符串


下一篇:day6 淘宝定位