题解 | #计算某字符出现次数#
计算某字符出现次数
http://www.nowcoder.com/practice/a35ce98431874e3a820dbe4b2d0508b1
package com.company.niuke;
import java.util.Scanner;
/**
* @ProjectName: leetcode
* @Package: com.company.niuke
* @ClassName: Main
* @Author: Administrator
* @Description: 牛客网测试
* @Date: 2022/2/11 20:30
* @Version: 1.0
*/
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
char[] str = scanner.nextLine().toLowerCase().toCharArray();
String ch = scanner.nextLine().toLowerCase();
int num = 0;
for (int i = 0; i < str.length; i++) {
if (ch.equals(String.valueOf(str[i]))) {
num++;
}
}
System.out.println(num);
}
}