请在 下方输入 要搜索的题目:

给定一个句子,统计单词中字母的出现次数(字母不区分大小写,全部按照小写计算)。

给定一个句子,统计单词中字母的出现次数(字母不区分大小写,全部按照小写计算)。

发布时间:2025-03-01 10:10:57
推荐参考答案 ( 由 快搜搜题库 官方老师解答 )
联系客服
答案:参考答案:参考代码import java.util.Scanner;public class countChar {public static void main(String[] args) {//输入需要检测的字符串System.out.print("Input String :");Scanner str0 = new Scanner(System.in);String s = str0.next();System.out.println("the String is :" s);s = s.toLowerCase(); //将字符串转换为小写//输入需要统计的字符System.out.print("Input char :");Scanner str1 = new Scanner(System.in);String s1 = str1.next();char c = s1.charAt(0);System.out.println("Input char is :" c);int count = 0; //统计出现次数变量for (int i = 0; i < s.length(); i ) {char ch = s.charAt(i);if (ch == c) {count ;}}System.out.println("The times is :" count);}}
专业技术学习
专业技术学习
搜搜题库系统