编写一个application程序实现如下功能:接受命令行中给出的一个字符串,先将字符串原样输出,然后判断该穿的第一个字母是否为大写,若是大写则统计该串中大写字母的个数,并将所有大写字母输出。

package application3;


import java.util.Scanner;


public class application3 {


public static void main(String[] args) {

Scanner in = new Scanner(System.in);
String s= in.nextLine();
System.out.println(s);
char x = s.charAt(0);//判断第一个字母是不是为大写;
if(x >= 65 && x <= 90 )
{
int n=0;
char[] Arr = s.toCharArray();//把字符串变成字符串数组。
for(int i=0 ; i<=s.length()-1;i++)//注意数组越界
{
if( Arr[i] >= 'A' && Arr[i] <= 'Z')
{

System.out.println("输出大写字母"+Arr[i]);
n++;
}
}
System.out.println("输出大些字母个数:"+n);

}
else {
System.out.println("第一个字母不是大写字母!");
}


}


}
posted @ 2018-05-05 14:12  jiaqi-zhang  阅读(626)  评论(0编辑  收藏  举报