题解 | #计算某字符出现次数#
计算某字符出现次数
http://www.nowcoder.com/practice/a35ce98431874e3a820dbe4b2d0508b1
接收来的全是字符串,串全转大写,后取得目标字符,循环比较。
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class Main {
public static void main(String[] args) throws NumberFormatException, IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String str = (br.readLine().trim());
str = str.toUpperCase();
String T = br.readLine().trim().toUpperCase();
char t = T.charAt(0);
int times = 0;
for(int i=0;i<str.length();i++) {
if(str.charAt(i)==t) times++;
}
System.out.print(times);
}
}