//方法一
public class Capitalized {
char[] cs = { 'T', 'o', 'd', 'a', 'y', ' ', 'i', 's', ' ', 's', 'u', 'n',
'n', 'y', '!' };
// 构造方法
public Capitalized() {
}
public void printCapitalized() {
int i;
for (i = 0; i
i = i + 1;
cs[i]=Character.toUpperCase(cs[i]);
}
}
for (i = 0; i< cs.length; i++) {
System.out.print(cs[i]);
}
}
public static void main(String[] args) {
new Capitalized().printCapitalized();
}
}
//方法二
public class Capitalized {
public static void main(String[] args) {
String s="today is sunny!";
String arr[]=s.trim().split("\\s+");
if(s.length()>0)
for (int i = 0; i < arr.length; i++) {
arr[i]=Character.toUpperCase(arr[i].charAt(0))+arr[i].substring(1);
System.out.print(arr[i]+" ");
}
}
}