import java.util.Scanner; public class Main26 { /*计算字符个数 写出一个程序,接受一个有字母和数字以及空格组成的字符串,和一个字符, 然后输出输入字符串中含有该字符的个数。不区分大小写。*/ public static void main(String[] args) { Scanner sc = new Scanner(System.in); String str1 = sc.nextLine();//是一行才能通过,如果是next 则显示答案错误? String s =sc.next(); sc.close(); char ch[] = str1.toUpperCase().toCharArray(); int count = 0; s = s.toUpperCase(); for (int i = 0; i < ch.length; i++) { if(ch[i] == s.charAt(0)){ count++; } } System.out.println(count); } } |
|