题解 | #计算某字符出现次数#

计算某字符出现次数

https://www.nowcoder.com/practice/a35ce98431874e3a820dbe4b2d0508b1

import java.util.Scanner;

// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
    public static void main(String[] args) {
         Scanner in = new Scanner(System.in);
        String nextLine = in.nextLine().toUpperCase();
        String secondLine = in.nextLine().toUpperCase();
        int count = 0;
        String substring = "";


        while (true){

            if (nextLine.length() > 1) {
                substring = nextLine.substring(0, 1);
                if (secondLine.equals(substring)) {
                    count++;
                }
            } else {
                if (secondLine.equals(nextLine)) {
                    count++;
                }
                break;
            }

            if (nextLine.length() > 1) {
                nextLine = nextLine.substring(1);
            }


        }


        System.out.println(count);
    }
}

全部评论

相关推荐

小鹏、大疆、米哈游、MinMax小鹏上午投的下午就约面,进度未免也太快了
蛇年行大运fff:哥们 盗贴有意思吗,我发xhs上的给你搬过来了😅😅😅
点赞 评论 收藏
分享
07-15 18:09
门头沟学院 Java
点赞 评论 收藏
分享
能干的三文鱼刷了10...:公司可能有弄嵌入式需要会画pcb的需求,而且pcb能快速直观看出一个人某方面的实力。看看是否有面试资格。问你问题也能ai出来,pcb这东西能作假概率不高
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务