Java 练习英文语句首字母变大写

来源:互联网 发布:nginx记录ip 编辑:程序博客网 时间:2024/05/17 01:23

p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Monaco}p.p2 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Monaco; color: #4e9072}p.p3 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Monaco; color: #3933ff}p.p4 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Monaco; min-height: 15.0px}span.s1 {color: #931a68}span.s2 {color: #000000}span.s3 {color: #3933ff}span.s4 {color: #0326cc}span.Apple-tab-span {white-space:pre}

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]+" ");

}

输出结果:

p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Monaco}

If You Miss The Tran I An On 

原创粉丝点击