0 50%
1 35%
2 15%
0 出现的概率为50%
1 出现的概率为35%
2 出现的概率为15%
在这3个数中按以上概率取其中的一个数。
问题补充:
0? 50%
1? 35%
2? 15%
?
?
0 出现的概率为50%
1 出现的概率为35%
2 出现的概率为15%
?
在这3个数中按以上概率取其中的一个数。
?
谢谢bohemia,刚才我也弄了一个,呵呵,过来一看差不多。呵呵。
public class RandomTest {
private static Random RANDOM = new Random();
public static void main(String[] args) {List list = new ArrayList(); list.add(new Integer(25)); list.add(new Integer(40)); list.add(new Integer(35)); Collections.sort(list); System.out.println(list); int a = ((Integer) list.get(0)).intValue(); int b = ((Integer) list.get(1)).intValue(); int c = ((Integer) list.get(2)).intValue(); System.out.println("几率最大的数:" + c); System.out.println("中间数:" + (c + b)); Map map = new HashMap(); int x = 0; int y = 0; int z = 0; for (int i = 0; i < 1000000; i++) { int k = RANDOM.nextInt(); int j = Math.abs(k % 100); if (j <= c) { map.put("0", new Integer(++x)); } else if (j > c && j <= (c + b)) { map.put("1", new Integer(++y)); } else if (j > (c + b) && j < (a+b+c)) { map.put("2", new Integer(++z)); } } System.out.println(map); }
}
问题补充:
0? 50%
1? 35%
2? 15%
?
?
0 出现的概率为50%
1 出现的概率为35%
2 出现的概率为15%
?
在这3个数中按以上概率取其中的一个数。
?
问题补充:
0 50%
1 35%
2 15%
0 出现的概率为50%
1 出现的概率为35%
2 出现的概率为15%
在这3个数中按以上概率取其中的一个数。
谢谢bohemia,刚才我也弄了一个,呵呵,过来一看差不多。呵呵。
public class RandomTest {
private static Random RANDOM = new Random();
public static void main(String[] args) {
List list = new ArrayList();
list.add(new Integer(25));
list.add(new Integer(40));
list.add(new Integer(35));
Collections.sort(list);
System.out.println(list);
int a = ((Integer) list.get(0)).intValue();
int b = ((Integer) list.get(1)).intValue();
int c = ((Integer) list.get(2)).intValue();
System.out.println("几率最大的数:" + c);
System.out.println("中间数:" + (c + b));
Map map = new HashMap();
int x = 0;
int y = 0;
int z = 0;
for (int i = 0; i < 1000000; i++) {
int k = RANDOM.nextInt();
int j = Math.abs(k % 100);
if (j <= c) {
map.put("0", new Integer(++x));
} else if (j > c && j <= (c + b)) {
map.put("1", new Integer(++y));
} else if (j > (c + b) && j < (a+b+c)) {
map.put("2", new Integer(++z));
}
}
System.out.println(map);
}
}
问题补充:
0? 50%
1? 35%
2? 15%
?
?
0 出现的概率为50%
1 出现的概率为35%
2 出现的概率为15%
?
在这3个数中按以上概率取其中的一个数。
?
谢谢bohemia,刚才我也弄了一个,呵呵,过来一看差不多。呵呵。
public class RandomTest {
private static Random RANDOM = new Random();
public static void main(String[] args) {
List list = new ArrayList();
list.add(new Integer(25));
list.add(new Integer(40));
list.add(new Integer(35));
Collections.sort(list);
System.out.println(list);
int a = ((Integer) list.get(0)).intValue();
int b = ((Integer) list.get(1)).intValue();
int c = ((Integer) list.get(2)).intValue();
System.out.println("几率最大的数:" + c);
System.out.println("中间数:" + (c + b));
Map map = new HashMap();
int x = 0;
int y = 0;
int z = 0;
for (int i = 0; i < 1000000; i++) {
int k = RANDOM.nextInt();
int j = Math.abs(k % 100);
if (j <= c) {
map.put("0", new Integer(++x));
} else if (j > c && j <= (c + b)) {
map.put("1", new Integer(++y));
} else if (j > (c + b) && j < (a+b+c)) {
map.put("2", new Integer(++z));
}
}
System.out.println(map);
}
}