秋日恋轩 2021-06-27 09:16 采纳率: 57.1%
浏览 11
已结题

有会写的么,麻烦私发我一下

 

  • 写回答

1条回答 默认 最新

  • 一剑荒芜 2021-06-28 09:56
    关注
    public class CountStr{
    
        public static void main(String[] args) {
            System.out.println(getStrCount(getStr()));
        }
    
        public static String getStr(){
            Scanner scanner = new Scanner(System.in);
            System.out.print("请输入要统计字符数量的字符串:");
            return scanner.next();
        }
    
        public static HashMap<Character, Integer> getStrCount(String str){
            HashMap<Character, Integer> map = new HashMap<>();
            for (int i = 0; i < str.length(); i++){
                map.merge(str.charAt(i), 1, Integer::sum);
            }
            return map;
        }
    
    }
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

问题事件

  • 系统已结题 7月1日
  • 已采纳回答 6月23日

悬赏问题

  • ¥15 安霸cv22 + rtl8211f 千兆,udp传输丢包
  • ¥15 关于区块链和边缘环境搭建的相关问题
  • ¥15 windows远程桌面断卡重连软件卡顿问题
  • ¥30 Unity 实现扫描效果
  • ¥15 HbuilderX检测不到安卓模拟器
  • ¥15 这个main已经在filename.obj中定义是什么错 C语言
  • ¥15 关于#linux#的问题:exsi8.0系统 怎么更改web访问端口,不用80、443
  • ¥15 使用elementor设计样式
  • ¥15 谁能提供一个中文版的推销咨询网站连接?
  • ¥15 springboot项目程序启动报错