题解 | #计算某字符出现次数#
计算某字符出现次数
https://www.nowcoder.com/practice/a35ce98431874e3a820dbe4b2d0508b1
import java.util.Scanner;
public class Main{
public static void main(String[] args){
Scanner scanner = new Scanner(System.in);
String str = null;
String c = null ;
int f = 0;
while(scanner.hasNextLine()){
if(str == null){
str = scanner.nextLine();
}
else{
c = scanner.nextLine();
}
}
char[] char_arr = str.toCharArray();
Character char_of_c = c.toCharArray()[0];
for(char i : char_arr){
if(Character.toLowerCase(char_of_c) == Character.toLowerCase(i)){
f++;
}
}
System.out.println(f);
}
}
京东工作强度 428人发布
查看15道真题和解析