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

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

http://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;

    }
}
全部评论

相关推荐

01-04 11:28
已编辑
广州华立学院 Java
程序员花海:实习内容写的看起来太偏向于技术了 要结合业务 很多同学搞反了 其实业务才是最重要的 要避免这种单纯罗列技术栈的格式
简历被挂麻了,求建议
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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