题解 | #统计一句话中重复单词的个数#

统计一句话中重复单词的个数

https://www.nowcoder.com/practice/2128e598b5a5407195c31175b5b33360

import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String line = scanner.nextLine();
        //HashMap+LinkedList
        Map<Character, Integer> map = new LinkedHashMap<Character, Integer>();
        //write your code here......
        for(int i = 0;i<line.length();i++){
            char c = line.charAt(i);
            if(c!=' '){
                if(map.containsKey(c)){
                map.put(c,map.get(c)+1);
            }else{
                map.put(c,1);
            }

            }else{
                continue;
            }
            

        }
        Set<Map.Entry<Character, Integer>> entrys = map.entrySet();
        for (Map.Entry<Character, Integer> entry : entrys) {
            System.out.println(entry.getKey() + ":" + entry.getValue());
        }
        
    }
}

全部评论

相关推荐

08-06 08:33
四川大学 Java
OPPO官方内推:卧槽!!!啥破公司啊!!!
投递OPPO等公司10个岗位
点赞 评论 收藏
分享
在秋招的河老师很爱吃:40岁失业 假如22岁开始工作 18年前 2007年那个时候如何 2015年开始互联网爆发 这个时候有了8年经验 然后黄金10年 你想想这些年挣了多少 这要是进的时候某个大厂 这辈子根本花不完了
你找实习最大的坎坷是什么
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务