首页 > 其他 > 详细

计算字符个数

时间:2017-03-14 18:46:09      阅读:172      评论:0      收藏:0      [点我收藏+]

题目描述

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

输入描述:

输入一个有字母和数字以及空格组成的字符串,和一个字符。

输出描述:

输出输入字符串中含有该字符的个数。

输入例子:
ABCDEF
A

import java.util.*;
public class Main{
    public static int getCount(String s,String c){
    int count=0;
    String s1=s.toUpperCase();
    String c1=c.toUpperCase();
    char c2=c1.charAt(0);
    for (int j=0;j<s1.length() ;j++ )
    {
        if(c2==s1.charAt(j)){
            count++;
        }
        else continue;
    }
    return count;
     
    }
    public static void main(String[] args){
        Scanner input =new Scanner(System.in);
        String s =input.nextLine();
        String c=input.nextLine();
        int i=getCount(s,c);
        System.out.println(i);
    }
}

计算字符个数

原文:http://www.cnblogs.com/code666/p/6549670.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!