随机数,这属于闲的。。。。
public static void main(String[] args) {int res = 1;int laziji = 0;int ganguotu = 0;HashMap<String, Integer> map = new HashMap<>();map.put("辣子鸡", laziji);map.put("干锅兔", ganguotu);for (int i = 0; i < 1000; i++) {// 此处获得 1-2之间的随机整数;//(int)(最小值+Math.random()*(最大值-最小值+1))res = (int) (1 + Math.random() * 2);String resStr = res == 1 ? "辣子鸡" : "干锅兔";Integer integer = map.get(resStr);integer += 1;map.put(resStr, integer);}System.out.println("辣子鸡:" + map.get("辣子鸡"));System.out.println("干锅兔:" + map.get("干锅兔"));
}
随机数,这属于闲的。。。。
public static void main(String[] args) {int res = 1;int laziji = 0;int ganguotu = 0;HashMap<String, Integer> map = new HashMap<>();map.put("辣子鸡", laziji);map.put("干锅兔", ganguotu);for (int i = 0; i < 1000; i++) {// 此处获得 1-2之间的随机整数;//(int)(最小值+Math.random()*(最大值-最小值+1))res = (int) (1 + Math.random() * 2);String resStr = res == 1 ? "辣子鸡" : "干锅兔";Integer integer = map.get(resStr);integer += 1;map.put(resStr, integer);}System.out.println("辣子鸡:" + map.get("辣子鸡"));System.out.println("干锅兔:" + map.get("干锅兔"));
}