题解 | #计算某字符出现次数#
计算某字符出现次数
https://www.nowcoder.com/practice/a35ce98431874e3a820dbe4b2d0508b1
最基础的方法😂
import java.io.IOException;
import java.util.*;
public class Main {
public static void main(String[] args) throws IOException {
Scanner sc = new Scanner(System.in);
int temp = 0;
String str = sc.nextLine();
String str1 = sc.nextLine();
String[]arr = str.split("");
for(int i=0;i<arr.length;i++){
if(arr[i].equalsIgnoreCase(str1)){
temp++;
}
}
System.out.println(temp);
}
#华为笔试#
import java.io.IOException;
import java.util.*;
public class Main {
public static void main(String[] args) throws IOException {
Scanner sc = new Scanner(System.in);
int temp = 0;
String str = sc.nextLine();
String str1 = sc.nextLine();
String[]arr = str.split("");
for(int i=0;i<arr.length;i++){
if(arr[i].equalsIgnoreCase(str1)){
temp++;
}
}
System.out.println(temp);
}
}
