写出一个程序,接受一个有字母和数字以及空格组成的字符串,和一个字符,然后输出输入字符串中含有该字符的个数。不区分大小写。

 

import java.util.Scanner;

 
class Main {
    public static void main (String[] args) {
        Scanner s = new Scanner(System.in);
        String st = null;
        char c = ' ';
        int count = 0;
        while (s.hasNext()) {
            st = s.next();
            c = s.next().charAt(0);
        }
        for (int i = 0; i < st.length(); i ++) {
            if (st.charAt(i) == c) {
                count ++;
            }
        }
        System.out.println(count);
    }
}
 
 
 
import java.util.*;
public class Main {
 
    /**
     * @param args
     */
    public static void main(String[] args) {
        // TODO Auto-generated method stub
        Scanner in = new Scanner(System.in);
        while (in.hasNext()) {
            String str1 = in.next();
            String str2=in.next();
            int cnt=0;
            for(int i=0;i<str1.length();i++)
            {
                if (str1.charAt(i)==str2.charAt(0)) {
                    cnt++;
                }
            }
            System.out.println(cnt);
        }
        in.close();
    }
 
}
posted on 2015-12-21 14:55  小飞虫子  阅读(181)  评论(0编辑  收藏  举报