提示:您可在线编辑运行本教程的实例 - 运行实例,去试试!
大写字符串中的字符
public class ComputeInitials { public static void main(String[] args) {/**时 代 J a v a 公 众 号 - nowjava.com**/ String myName = "Fred F. Flintstone"; StringBuffer myInitials = new StringBuffer(); int length = myName.length(); for (int i = 0; i < length; i++) { if (Character.isUpperCase(myName.charAt(i))) { myInitials.append(myName.charAt(i)); } } System.out.println("My initials are: " + myInitials); } }