题解 | #计算某字符出现次数#
计算某字符出现次数
https://www.nowcoder.com/practice/a35ce98431874e3a820dbe4b2d0508b1
1、全部转换成小写之后在做差
import java.util.Scanner; // 注意类名必须为 Main, 不要有任何 package xxx 信息 public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); //首先全部转换为小写 String str = in.nextLine().toLowerCase(); String c = in.nextLine().toLowerCase(); //将第二次读入的字符串 在第一次读入的字符串中删除 String newstr = str.replaceAll(c, ""); //输出结果为新旧字符串之差 int count = str.length() - newstr.length(); System.out.println(count); } }