题解 | #计算某字符出现次数#
计算某字符出现次数
https://www.nowcoder.com/practice/a35ce98431874e3a820dbe4b2d0508b1
都转化成小写或大写再转成 char 数组
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class Main { public static void main(String[] args) { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int count = 0; try { char[] arr = br.readLine().toLowerCase().toCharArray(); char[] arr1 = br.readLine().toLowerCase().toCharArray(); for (int i = 0; i < arr.length; i++) { if (arr[i] == arr1[0]) { count++; } } } catch (IOException e) { throw new RuntimeException(e); } System.out.println(count); } }