首页 > 技术文章 > 判断字符是否为大写字母

gy7777777 2020-07-14 15:13 原文

 

 

/*
    先把字符串转为字符数组,遍历字符数组,若ASCII码在65-90之间,则count+1
*/
import java.util.*;
public class Main{
    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);
        while(sc.hasNext()){
            String str = sc.nextLine();
            int count = 0;
            char ss[] = str.toCharArray();
            for (int i = 0; i < ss.length; i++){
                if(ss[i]>='A' && ss[i]<='Z'){
                    count++;
                }
            }
            System.out.println(count);
        }
    }
}

 

推荐阅读