判断子字符出现次数

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);

}

 

}

posted @ 2016-10-13 15:28  mabelfdm  阅读(135)  评论(0编辑  收藏  举报