1. 程式人生 > >一種將英文文章字串每個單詞首字母轉成大寫字母的方法

一種將英文文章字串每個單詞首字母轉成大寫字母的方法

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);
}
}