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

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

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());
        }
        
    }
}

全部评论

相关推荐

友友们,我实在是不太明白,校招的话现在大多也是提前实习,然后转正也是需要考核的,考核通过才能转正,那这跟实习转正有什么区别啊
苦闷的仰泳鲈鱼刷了1...:提前实习,是让你提前熟悉业务的,后续是入职后可以减少试用期的(大部分是包入职的);转正实习,要是hc不够或者其他原因,让你正式offer可能都没有,这个风险很大。 ---个人看法和了解到的。
点赞 评论 收藏
分享
10-16 23:37
已编辑
门头沟学院 运营
据说名字越长别人越关...:西交做运营吗。。就业市场已经颠了
简历被挂麻了,求建议
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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