A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

© huan111 中级黑马   /  2016-5-25 00:02  /  797 人查看  /  9 人回复  /   0 人收藏 转载请遵从CC协议 禁止商业使用本文

.将"hello world"字符串中每个单词的首字母转换成大写其余字母还是小写(不能直接输出 Hello World而是用代码实现)????

9 个回复

倒序浏览
public class Test {
       public static void main(String[] args) {
             String s = "hello world";
             String[] arr = s.split(" ");
             StringBuffer sb = new StringBuffer();
             for (int i = 0; i < arr.length; i++) {
        sb.append(arr[i].substring(0, 1).toUpperCase().concat(arr[i].substring(1).toLowerCase()));
             }
                System.out.println(sb);
        }
}
回复 使用道具 举报 1 0
18735346124 发表于 2016-5-25 00:40
public class Test {
       public static void main(String[] args) {
             String s = "hello w ...

谢谢,.append( " " )再在中间加一个空格
回复 使用道具 举报
瞧着熟练的手法 ......顶一个
回复 使用道具 举报
public class 题目 {
       public static void main(String[] args) {
               String s = "hello world";
               String s1 =s.replace('h', 'H');
               String s2 =s1.replace('w', 'W');
              
               System.out.println(s2);
       }   
}
回复 使用道具 举报
驰马定中原 发表于 2016-5-25 01:54
public class 题目 {
       public static void main(String[] args) {
               String s = "hello world" ...

这样可以吧
回复 使用道具 举报
驰马定中原 发表于 2016-5-25 01:54
public class 题目 {
       public static void main(String[] args) {
               String s = "hello world" ...

这样可以吧
回复 使用道具 举报
public class 题目 {
       public static void main(String[] args) {
               String s = "hello world";
               char[] cha = s.toCharArray();
               StringBuffer sb = new StringBuffer();
               for (int i = 0; i < cha.length; i++) {
                       if (cha[i]=='h') {
                                cha[i]='H';
                        }
                       if (cha[i]=='w') {
                                cha[i]='W';
                        }
                       sb.append(cha[i]);
                }
               System.out.println(sb);
回复 使用道具 举报
好简单.........
回复 使用道具 举报
  1. String str = "hello world";
  2.                 System.out.println(str.substring(0,1).toUpperCase()+str.substring(1,6)+str.substring(6,7).toUpperCase()+str.substring(7));
复制代码
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 加入黑马