题解 | #计算某字符出现次数#
计算某字符出现次数
https://www.nowcoder.com/practice/a35ce98431874e3a820dbe4b2d0508b1
import java.io.*;
// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br= new BufferedReader(new InputStreamReader(System.in ));
//输入对象流
String str1=br.readLine();
String str2=br.readLine();
//一、二行字符转化为字符串
String p=str1.toUpperCase();
String c=str2.toUpperCase();
//把所有的字符串转化为大写
char ps[]=p.toCharArray();
char cs=c.charAt(0);
//把字符串转换成数组
int times=0;
for(int i=0;i<ps.length;i++){
if(cs==ps[i]){
times++;
}
}
//把cs数组遍历ps中,把相同的字符用times记录下来
System.out.println(times);
}
}
小天才公司福利 1263人发布


