大厂Java笔试题之判断字母大小写

java 复制代码
/**
 * 题目:如果一个由字母组成的字符串,首字母是大写,那么就统计该字符串中大写字母的数量,并输出该字符串中所有的大写字母。否则,就输出
 * 该字符串不是首字母大写
 */
public class Demo2 {
    public static void main(String[] args) {
//        outputWordAscii();
        Scanner scanner = new Scanner(System.in);
        while (scanner.hasNextLine()) {
            String s = scanner.nextLine();
            char[] chars = s.toCharArray();
            if (isUpperCase(chars[0])) {
                int upperCaseCount = getUpperCaseCount(chars);
                System.out.print(upperCaseCount + " ");
                System.out.println();
            } else {
                System.out.println("不是首字母大写");
            }
        }
        scanner.close();
    }

    public static boolean isUpperCase(char aChar) {
        if (aChar >= 65 && aChar <= 90) {
            return true;
        } else {
            return false;
        }
    }

    public static int getUpperCaseCount(char[] chars) {
        int res = 0;
        for (int i = 0; i < chars.length; i++) {
            if (isUpperCase(chars[i])) {
                System.out.print(chars[i] + " ");
                res++;
            }
        }
        return res;
    }

    public static void outputWordAscii() {
        for (int i = 65; i <= 122; i++) {
            if (i > 90 && i< 97) {
                continue;
            }
            System.out.print((char) i + " ");
        }
    }
}

如果大家需要视频版本的讲解,欢迎关注我的B站:

相关推荐
Highcharts.js2 分钟前
技术组合分析:Highcharts 的数据集成能力解析
java·前端·金融·echarts·saas·bi·highcharts
m0_734949795 分钟前
PHP怎么使用Eloquent Attribute Synthesis属性合成_Laravel多源数据融合【指南】
jvm·数据库·python
香山上的麻雀10089 分钟前
由 Rust 开发的能大幅降低LLM token消耗的高性能 CLI 代理工具 rtk
开发语言·后端·rust
Fleshy数模9 分钟前
玩转 Python:多线程、装饰器、视觉检测与正则匹配实战
开发语言·python·视觉检测
Lucas_coding9 分钟前
【xiaozhi-esp32-server-服务端全模块启动】 xiaozhi-server 获取6位有效验证码
python
薛定猫AI10 分钟前
【深度解析】Qwen 3.6 Max Preview:面向智能体编码、视觉推理与 Three.js 前端生成的能力拆解
开发语言·前端·javascript
❆VE❆12 分钟前
python实战(一):对接AI大模型并应用
开发语言·人工智能·python·ai
qq_3729069314 分钟前
CSS怎么在flex布局中实现项目均分间距_设置justify-content space-evenly
jvm·数据库·python
格林威17 分钟前
堡盟Baumer VCX系列工业相机供电与触发:网口(GigE) vs USB3.0
开发语言·人工智能·数码相机·计算机视觉·视觉检测·工业相机·高速相机
yangtuoni17 分钟前
vscode调试C++ python相关配置
c++·vscode·python