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

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

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

import java.util.Scanner;
import java.lang.String;
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......
        String newStr=str.replace(word,"xx");  //替换
        return newStr.length()-str.length();//用替换的长度-原长度
    }
}

全部评论

相关推荐

运营3年修炼中接简历辅导:你的科研项目经历里,只写了你的动作,没有写你的思考和成果,不要只写使用什么进行了什么,这等于罗列你的任务,简历是为了突出你的优秀,你在什么样的任务背景下,克服了什么样的困难,针对性地做了哪些事情,最后达成了什么成果(用数据体现你的成果和效率)
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务