黑马程序员技术交流社区

标题: 每个单词的首字母转换成大写其余还是小写字母 [打印本页]

作者: 487941230    时间: 2016-7-31 22:14
标题: 每个单词的首字母转换成大写其余还是小写字母
public class Demo {
        public static void main(String[] args) {

String str = "goOd gooD stUdy dAy dAy up";
                str = str.toLowerCase();
                String[] arr = str.split(" ");
                for(int i = 0; i < arr.length; i++) {
                        arr[i] = arr[i].substring(0,1).toUpperCase().concat(arr[i].substring(1,arr[i].length())).concat(" ");
                }
               
                for(int i = 0; i < arr.length; i++) {
                        System.out.print(arr[i]);
                }
        }

}




欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/) 黑马程序员IT技术论坛 X3.2