题解 | #计算某字符出现次数#
计算某字符出现次数
https://www.nowcoder.com/practice/a35ce98431874e3a820dbe4b2d0508b1
import java.util.Scanner;
/**
* 写出一个程序,接受一个由字母、数字和空格组成的字符串,和一个字符,然后输出输入字符串中该字符的出现次数。(不区分大小写字母),数据范围1<=n<=1000
*
* @author : DoubleLz
* @date : 2023/8/1 0001 12:32
* @description: some description
*/
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
// 输入字符串
String str = sc.nextLine().toLowerCase();
int strLength = str.length();
if (strLength >= 1 && strLength <= 1000) {
// 要查找的字符
String ch = sc.nextLine().toLowerCase();
String newStr = str.replace(ch, "");
System.out.println(strLength - newStr.length());
}
}
}

