/**
* 第一个字母转大写
*/
import java.util.*;
public class acm2026 {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
while (in.hasNext()) {
String str = in.nextLine();
char[] c = new char[1];
String[] a = str.split(" ");
for (int i = 0; i < a.length; i++) {
c[0] = a[i].charAt(0);
String tp = new String(c);
/*
* replaceFirst(String regex, String replacement) 使用给定的
* replacement 替换此字符串匹配给定的正则表达式的第一个子字符串。
*/
if (i != a.length - 1)
System.out.print(a[i].replaceFirst(tp, tp.toUpperCase())
+ " ");
else
System.out.println(a[i].replaceFirst(tp, tp.toUpperCase()));
}
}
}
}
/*
* for(int i=0; i<a.length-1; i++) { c[0] = a[i].charAt(0); String tp = new
* String(c); System.out.print(a[i].replaceFirst(tp, tp.toUpperCase()) + " "); }
* c[0] = a[a.length-1].charAt(0); String tp = new String(c);
* System.out.print(a[a.length-1].replaceFirst(tp, tp.toUpperCase()));
* System.out.println();
*/acm2026
原文:http://blog.csdn.net/a736933735/article/details/44724711