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

计算某字符出现次数

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

import java.util.Scanner;
public class Main{
    public static void main(String[] args){
       /**
         1 用输入输出Scanner
         2 用sc.hasNextLine接收两个目标字符串
         3 遍历第一行的字符串并和第二行比较 用计数器统计出现次数
         4 输出计算器
        */
        Scanner sc = new Scanner(System.in);
        String str = sc.nextLine();
        String s = sc.nextLine();
        char[] ac = str.toCharArray();// 字符串转字节串
        int count = 0;
        for(int i = 0; i <ac.length;i++){
            if(s.equalsIgnoreCase(String.valueOf(ac[i]))){
              count++;
            }
        }
        System.out.println(count);

    }
}

全部评论

相关推荐

03-04 19:02
云南大学 Java
Yki_:没挂,只是没人捞,该干啥干啥,等着就好了
点赞 评论 收藏
分享
不放弃的小鱼干很洒脱:好可爱的离职理由
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务