编辑代码

package FristJspHomework;

/**
 * 4、编写这样一个程序找出字符串“My name is Tom, I come from China.”中的大写字母,并打印输出。
 */
public class UpperCaseString {
	public static void main(String[] args) {
		GetUpperCase();
	}
	
	/**
	 * 输出字符串中的大写字母,并输出。
	 */
	public static void GetUpperCase() {
		StringBuffer sb = new StringBuffer();
		
		String s = "My name is Tom, I come from China.";
		/**
		 * 将字符串转换为char数组
		 */
		char[] arr = s.toCharArray();
		
		/**
		 * 遍历获取大写字母
		 */
		for(int i = 0 ; i < arr.length; i++) {
			if(arr[i] > 'A' && arr[i] < 'Z') {
				// 进行字符串拼接
				sb.append(arr[i]);
			}
		}
		System.out.println(sb);
	}
}