字符计数

计算字符个数

http://www.nowcoder.com/questionTerminal/a35ce98431874e3a820dbe4b2d0508b1

import java.util.Scanner;

/**
 * @Auther: 206069780
 * @Date: 2020/4/22 21:21
 */
public class Main {
    public static void main(String[] args) {
        /*
          *1、从键盘输入字符串并将其转为小写/大写,我这采用的是小写:toLowerCase()
          *2、遍历字符串,统计要需要统计的字符个数并输出
        */
        Scanner scanner=new Scanner(System.in);
        String string=scanner.nextLine().toLowerCase();
        char pattern = scanner.next().toLowerCase().charAt(0);
        match(string,pattern);

    }
    public static void match(String str1,char str2){
        int count=0;
       for(int i=0;i<str1.length();i++){

           if(str1.charAt(i)==str2)count++;
       }
        System.out.println(count);
    }

}
全部评论

相关推荐

我:“加班需要有加班工资。”&nbsp;hr:“为什么?”&nbsp;哈哈哈哈哈哈哈离大谱
juntenor:你确实太理想化了,对社会不了解呀。这个和HR没有关系,这是国内特色,不然怎么还会有外包就这种逆天的存在呢。
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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