码迷,mamicode.com
首页 > 其他好文 > 详细

华为OJ:计算字符个数

时间:2017-05-01 17:11:12      阅读:180      评论:0      收藏:0      [点我收藏+]

标签:character   lower   ase   for   ati   number   art   public   article   

由于区分大写和小写,所以要用toUpperCase()和toLowerCase()两个函数同一时候与charAt得到的字符比較。

import java.util.Scanner;

public class countCharNumber {
	public static void main(String args[]){
		Scanner input=new Scanner(System.in);
		String s=input.nextLine();
		char c=input.next().charAt(0);
		int count=0;
		for(int i=0;i<s.length();i++){
			if(Character.toLowerCase(c)==s.charAt(i)||Character.toUpperCase(c)==s.charAt(i))count++;
		}
		System.out.println(count++);
	}
}

华为OJ:计算字符个数

标签:character   lower   ase   for   ati   number   art   public   article   

原文地址:http://www.cnblogs.com/mthoutai/p/6792145.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!