题解 | 统计字符串中字母出现次数

统计字符串中字母出现次数

https://www.nowcoder.com/practice/83350872bdb5406fa706895d5efb1c55

import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        String string = "H e l l o ! n o w c o d e r";
        Scanner scanner= new Scanner(System.in);
        String word = scanner.next();
        scanner.close();
        System.out.println(check(string, word));
    }

    public static int check(String str, String word) {

        //write your code here......
        int count=0;
        for(int i=0;i<str.length();i++){
            if(str.charAt(i)==word.charAt(0))
            {
                count++;
            }
        }
        return count;

    }
}

全部评论

相关推荐

05-30 13:04
已编辑
门头沟学院 算法工程师
智谱和米哈游都是ai大模型agent的业务钱的话还是米更多,几乎翻倍了,有没有老哥是两个公司其中一个的,能问问转正率咋样嘛,我问的hr回答都是做的好就可以转正暑期实习
码农索隆:选米哈游:短期高薪、敢承担风险、具备强创新能力,且愿押注游戏AI赛道。 选智谱:稳定性与行业通用能力积累,接受薪资差距以换取更稳妥的职业基础。
投递北京智谱华章科技等公司7个岗位 > 实习期间如何提升留用概率?
点赞 评论 收藏
分享
frutiger:逆天,我家就安阳的,这hr咋能说3k的,你送外卖不比这工资高得多?还说大厂来的6k,打发叫花子的呢?这hr是怎么做到说昧良心的话的
点赞 评论 收藏
分享
心中的变压器:简历需要突出重点
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务