• 首页 首页 icon
  • 工具库 工具库 icon
    • IP查询 IP查询 icon
  • 内容库 内容库 icon
    • 快讯库 快讯库 icon
    • 精品库 精品库 icon
    • 问答库 问答库 icon
  • 更多 更多 icon
    • 服务条款 服务条款 icon

找到保存最小整数值的 HashMap 的键

用户头像
it1352
帮助7

问题说明

我正在为需要学习最常用单词的年轻学生创建一个教育游戏.我随机选择列表中的三个单词,将它们显示在屏幕上,播放三个单词之一的录音,然后学生必须选择已经发音的单词.我记录了他们每个单词猜了多少次.通过这种方式,我可以为何时应该向学生介绍新单词设置一个标准.When three of the words are picked I'll like to pronounce the word that the student has had least exposure to.

I'm creating an educational game for young students who needs to learn the most common words. On random I pick three words of the list, show them on the screen, play an audio recording of one of the three words and then the student has to pick the word that has been pronounced. I keep track of how many times they have guessed each word. In that way I can set up a criteria for when new words should be introduced to the student. When three of the words are picked I'll like to pronounce the word that the student has had least exposure to.

我有一个名为 words 的 HashMap,其中包含单词,以及学生猜出单词的次数的整数值.

I have a HashMap called words, which contains the words, and a integer value of how many times the student guessed the word.

  HashMap<String,Integer>  words 

它包含 10 - 120 个键/词.我想创建一个方法,它将三个哈希映射键作为参数,它可以返回具有最低要求键值的字符串/键.

It contains between 10 - 120 keys/words. I'll like to create a method, which takes three of the hash map keys as parameters, that can return the String/key having the lowest value of the keys asked for.

我很难让它按预期工作,如果能提供任何帮助,我将不胜感激.

I have had trouple getting this to work as intended and I'd appreciate any help.

正确答案

#1

这个怎么样?

private String getMinKey(Map<String, Integer> map, String... keys) {
    String minKey = null;
    int minValue = Integer.MAX_VALUE;
    for(String key : keys) {
        int value = map.get(key);
        if(value < minValue) {
            minValue = value;
            minKey = key;
        }
    }
    return minKey;
}

这篇好文章是转载于:学新通技术网

  • 版权申明: 本站部分内容来自互联网,仅供学习及演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,请提供相关证据及您的身份证明,我们将在收到邮件后48小时内删除。
  • 本站站名: 学新通技术网
  • 本文地址: /reply/detail/tangicagc
系列文章
更多 icon
同类精品
更多 icon
继续加载