問題描述
我正在為需要學習最常用單詞的年輕學生創建一個教育游戲.我隨機選擇列表中的三個單詞,將它們顯示在屏幕上,播放三個單詞之一的錄音,然后學生必須選擇已經發音的單詞.我記錄了他們每個單詞猜了多少次.通過這種方式,我可以為何時應該向學生介紹新單詞設置一個標準.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.
推薦答案
這個怎么樣?
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;
}
這篇關于找到保存最小整數值的 HashMap 的鍵的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!