public class TxtText {
public static void main(String[] args) {
//首字母大写
String str="if you miss the tran i an on";
//1.按空格切割
String strArr[]=str.split(" ");
//2.初始化一个结果数组
String resultArr[]=new String[strArr.length];
//3.遍历
for (int i = 0; i < strArr.length; i++) {
resultArr[i]=strArr[i].replaceFirst(strArr[i].substring(0,1),strArr[i].substring(0,1).toUpperCase());
}
for (int i = 0; i < resultArr.length; i++) {
System.out.print(resultArr[i]+" ");
}
输出结果:
If You Miss The Tran I An On