黑马程序员技术交流社区

标题: 纠结了两天终于有结果了,拿去不谢。 [打印本页]

作者: 刘文秀    时间: 2016-7-31 23:50
标题: 纠结了两天终于有结果了,拿去不谢。
package com.itheima1;
/*
* 6.将"goOd gooD stUdy dAy dAy up"
* 每个单词的首字母转换成大写其余还是小写字母(不许直接输出good good study day day up 要用代码实现)
*/
public class Sixth_BigtoSmall {
        public static void main(String[] args) {
                String str = "goOd gooD stUdy dAy dAy up";
                String[] str2 = str.trim().split(" ");
                for (int i = 0; i < str2.length; i++) {
                        char ch = Character.toUpperCase(str2[i].charAt(0));
                        String str3 = str2[i].substring(1).toLowerCase();
                        System.out.print((ch + str3) + " ");
                }
               
        }
}



作者: itismyhao    时间: 2016-8-1 01:55
看了下题,练习了一下
咱俩基本大同小异
[Java] 纯文本查看 复制代码
class Demo2
{
        public static void change(String str)
        {
                String[] arr=str.split(" ");
                for(int i=0;i<arr.length;i++)
                {
                        String a=String.valueOf(arr.charAt(0)).toUpperCase();
                        String b=arr.substring(1,arr.length()).toLowerCase();
                        System.out.print(a+b+" ");
                }
        }
        public static void main(String[] args)
        {
                String str = "goOd gooD stUdy dAy dAy up";
                change(str);
        }
}





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