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

华为OJ:计算字符个数

时间:2014-07-09 09:26:17      阅读:232      评论:0      收藏:0      [点我收藏+]

标签:style   java   for   line   new   ar   

因为区分大小写,所以要用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:计算字符个数,布布扣,bubuko.com

华为OJ:计算字符个数

标签:style   java   for   line   new   ar   

原文地址:http://blog.csdn.net/whu_sky/article/details/37583961

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