/*
* 题目描述
写出一个程序,接受一个有字母和数字以及空格组成的字符串,和一个字符,然后输出输入字符串中含有该字符的个数。不区分大小写。
输入描述:
输入一个有字母和数字以及空格组成的字符串,和一个字符。
输出描述:
输出输入字符串中含有该字符的个数。
示例1
输入
ABCDEF
A
输出
1
*/
package huawei;
import java.util.Scanner;
public class numOfA {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
String firstLine = (scanner.nextLine()).toLowerCase();
byte[] strings = firstLine.getBytes();
String character = scanner.nextLine();
byte[] chars = character.getBytes();
int count=0;
for (int i = 0; i < strings.length; i++) {
if (strings[i]==chars[0]) {
count++;
}
}
System.out.println(count);
}
}
华为机试,计算字符的个数
最新推荐文章于 2020-07-21 14:21:05 发布