判断子字符出现次数
import
java.util.Scanner;
public
class CharCount {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.print("Please input a String: ");
String inputString = input.nextLine();
System.out.print("Please input a char: ");
String inputChar = input.next();
char ch = inputChar.charAt(0);
int charCount = 0;
for(int i=0; i<inputString.length(); i++){
if(ch == inputString.charAt(i)){
charCount++;
}
}
System.out.println(charCount);
}
}