华为2

import java.util.Scanner;

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

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		//键盘输入
		Scanner sc=new Scanner(System.in);
		String str=sc.nextLine();
		String ch=sc.nextLine();
		//要做到无视大小写
//		String toUpperCase() 
//        使用默认语言环境的规则将此 String 中的所有字符都转换为大写。 
		String str1=str.toUpperCase();
		String ch1=ch.toUpperCase();
		//拿出这个位置的0索引的字符
//		 char charAt(int index) 
//         返回指定索引处的 char 值。 
		char ch2=ch1.charAt(0);
		     sc.close();
            judge(str1,ch2);
	}
	private static void judge(String str1,char ch2)
	{
//		String[] A=str.split(ch);
//		int len=A.length-1;
//		System.out.println(len);
		//本来想用这种发现,最后计试只有百分之90个通过率,放弃了
		//用遍历的形式
		int count=0;
		for(int i=0;i<str1.length();i++)
		{
		   //当字符串里面有值跟字符相等时
			if(str1.charAt(i) ==ch2)
			{
				count++;
			}
		}
		System.out.println(count);
	}

}

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值