题解 | #计算某字符出现次数#
计算某字符出现次数
https://www.nowcoder.com/practice/a35ce98431874e3a820dbe4b2d0508b1
import java.util.*; public class Main{ public static void main(String[] args){ Scanner in = new Scanner(System.in); while(in.hasNext()){ String str = in.nextLine().toLowerCase(); String s = in.nextLine().toLowerCase(); HashMap<Character,Integer> map = new HashMap<>(); for(char ss:str.toCharArray()){ if(ss==s.charAt(0)){ map.put(ss,map.getOrDefault(ss,0)+1); } } int len = (map.get(s.charAt(0))==null ? 0:map.get(s.charAt(0))); System.out.println(len); } } }