Czy ten kod jest poprawny ? Skoro losuję 1000 razy liczbę, to suma wartości też powinna dawać 1000, a tak nie jest. Np. zero wystąpiło 29 razy, 1 wystąpiła 13 razy, czyli 1+29....+.... powinno być 1000 tak ?
package zlabliczby;
import java.util.HashMap;
import java.util.Random;
public class ZlabLiczby {
public static void main(String[] args) {
//pierwszy klucz
Random random = new Random();
Integer[] tabKeys = new Integer[30];
HashMap<Integer, Integer> hashMap = new HashMap<Integer, Integer>();
for(int j=0; j<tabKeys.length; j++){
tabKeys[j] = j;
}
for(int k=0; k<tabKeys.length; k++){
for(int i=0; i<1000; i++){
hashMap.put(k, random.nextInt(30));
}
}
System.out.println(hashMap+"\n");
}
}
{0=29, 1=13, 2=12, 3=12, 4=25, 5=18, 6=13, 7=25, 8=1, 9=24, 10=15, 11=7, 12=22, 13=12, 14=5, 15=1, 17=16, 16=14, 19=0, 18=20, 21=11, 20=14, 23=28, 22=20, 25=2, 24=27, 27=4, 26=24, 29=21, 28=21}