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

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

}

}

全部评论

相关推荐

喜欢喜欢喜欢:这是我见过最长最臭的简历
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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