import java.util.Scanner;
public class Main{
public static int char_length(String s, String c){
int count = 0;
for(int i=0; i<s.length(); i++){
if(s.substring(i,i+1).equalsIgnoreCase(c)){
count++;
}
}
return count;
}
public static void main(String[] args){
Scanner in = new Scanner(System.in);
String s = in.nextLine();
String c = in.nextLine();
System.out.println(char_length(s,c));
}
}
The main methods used in the examples are:
the substring (the beginIndex int, int endIndex) :
This is a method to take a substring of a string, and if the beginindex endindex pitch is set to 1, that can take only a character.
equalsIgnoreCase (String anotherString) :
This is the equals () method compares the character case of neglect;
只要每天积累,一定会有收获!