题解 | #计算某字符出现次数#
计算某字符出现次数
https://www.nowcoder.com/practice/a35ce98431874e3a820dbe4b2d0508b1?tpId=37&tags=&title=&difficulty=0&judgeStatus=0&rp=1&sourceUrl=%2Fexam%2Foj%2Fta%3FtpId%3D37
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
// 注意 hasNext 和 hasNextLine 的区别
while (in.hasNext()) { // 注意 while 处理多个 case
String str = in.nextLine();
String c = in.next();
//分割成字符串数组
String[] strs = str.split("");
//字符出现次数
int count = 0;
for (int i = 0; i<str.length(); i++){
if (c.equalsIgnoreCase(strs[i])){
count++;
}
}
System.out.println(count);
}
}