1. 程式人生 > 其它 >統計輸入的大小寫字母個數

統計輸入的大小寫字母個數

示例:

public class day1011 {
public static void main(String[]args){
String str="sbvAYGcj2h75893";
int big=0;
int small=0;
int num=0;
int len=str.length();
for(int i=0;i<len;i++){
char c=str.charAt(i);

if(c>'A'&&c<'Z'){
big++;
}
if(c>'a'&&c<'z'){
small++;
}
if(c>'0'&&c<'9'){
num++;
}
}
System.out.println("大寫字母的個數為"+big);
System.out.println("小寫字母的個數為"+small);
System.out.println("數字的個數為"+num);
}
}

執行結果:

大寫字母的個數為2

小寫字母的個數為6

數字的個數為5