您的位置:首页 > 编程语言 > Java开发

一种将英文文章字符串每个单词首字母转成大写字母的方法

2016-11-19 10:47 423 查看
import java.util.Arrays;

public class newexercise3 {

public static void main(String[] args) {
String str =new String("If you were a teardrop;In my eye,For fear of losing you,I would never cry.And if the golden sun,Should cease to shine its light,Just one smile from you,Would make my whole world bright.");   
System.out.println(str);
byte []by=str.getBytes();
for(int i=0;i<by.length-1;i++){
switch(by[i]){
case 32:
case 33:
case 46:
case 59:
case 63:
if(by[i+1]>=65&&by[i+1]<=90){
continue;
}else{
by[i+1]=(byte) (by[i+1]-32);
num++;
}
}
}
String s =new String(by);
System.out.println(s);
}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  java String
相关文章推荐