問(wèn)題描述
我正在為需要學(xué)習(xí)最常用單詞的年輕學(xué)生創(chuàng)建一個(gè)教育游戲.我隨機(jī)選擇列表中的三個(gè)單詞,將它們顯示在屏幕上,播放三個(gè)單詞之一的錄音,然后學(xué)生必須選擇已經(jīng)發(fā)音的單詞.我記錄了他們每個(gè)單詞猜了多少次.通過(guò)這種方式,我可以為何時(shí)應(yīng)該向?qū)W生介紹新單詞設(shè)置一個(gè)標(biāo)準(zhǔn).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.
我有一個(gè)名為 words 的 HashMap,其中包含單詞,以及學(xué)生猜出單詞的次數(shù)的整數(shù)值.
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 個(gè)鍵/詞.我想創(chuàng)建一個(gè)方法,它將三個(gè)哈希映射鍵作為參數(shù),它可以返回具有最低要求鍵值的字符串/鍵.
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.
我很難讓它按預(yù)期工作,如果能提供任何幫助,我將不勝感激.
I have had trouple getting this to work as intended and I'd appreciate any help.
推薦答案
這個(gè)怎么樣?
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;
}
這篇關(guān)于找到保存最小整數(shù)值的 HashMap 的鍵的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!