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

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

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......
        char c=word.charAt(0);
        int i=0;
        int count=0;
        for(i=0;i<str.length();i++)
        {
            if(c==str.charAt(i))
            count++;
            
        }
        return count;

    }
}

全部评论

相关推荐

06-12 16:00
天津大学 Java
牛客30236098...:腾讯坏事做尽,终面挂是最破防的 上次被挂了后我连简历都不刷了
点赞 评论 收藏
分享
Ncsbbss:又想干活又想要工资,怎么什么好事都让你占了
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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