通過調用方法,在我的情況下countInNumbers將返回結果作爲數組。如何獲取並比較映射的值結果<Integer,Integer>
System.out.println(countIntInNumbers(Array));
結果:
{1=17, 2=10, 3=16, 4=17, 5=13, 6=22, 7=10, 8=15, 9=16, 10=19, 11=11, 12=15, 13=16, 14=13, 15=19, 16=17, 17=13, 18=21, 19=19, 20=15,}
我嘗試數字上取決於他們的總價值不同的表分開。 示例...我想顯示其總數在3到4之間的數字,以便與其他數字分開。
面對這個問題導致結果,你可能會注意到是地圖,因爲我是新的Java,我很困惑在這一點上。
任何人都可以建議從某件事開始?
更新::: countIntInNumbers方法如下
public static Map<Integer, Integer> countIntInNumbers(int[][] mat) {
Map<Integer, Integer> intOccurences = new HashMap<>();
for (int[] row : mat) {
for (int intInRow : row) {
Integer occurences = intOccurences.get(intInRow);
if (occurences == null) { // first occurrence
intOccurences.put(intInRow, 1);
} else { // increment
intOccurences.put(intInRow, occurences.intValue() + 1);
}
}
}
return intOccurences;
你能顯示'countIntInNumbers'的代碼? –
*我想打印所有數字,其總數在3和4 *之間。一個單一的數字除了它本身之外不能有一個總數。你想說什麼?上例中的預期輸出是什麼? *我很困惑在這一點上。*我也是如此。 – shmosel
發佈更新的方法; s代碼 – Annu