public class E60Probability {
public static void printProbility(int number
) {
final int MAX_VALUE
= 6;
int[][] probility
= new int[2][number
* MAX_VALUE
+ 1];
int flag
= 0;
for (int i
= 0; i
<= MAX_VALUE
; i
++)
probility
[flag
][i
] = 1;
for (int k
= 2; k
<= number
; k
++) {
for (int i
= 0; i
< k
; i
++)
probility
[1 - flag
][i
] = 0;
for (int i
= k
; i
< MAX_VALUE
* k
+ 1; i
++){
probility
[1 - flag
][i
] = 0;
for (int j
= 1; j
<= i
&& j
<= MAX_VALUE
; j
++){
probility
[1 - flag
][i
] += probility
[flag
][i
- j
];
}
}
flag
= 1 - flag
;
}
int total
= (int) Math
.pow(MAX_VALUE
, number
);
for (int i
= number
; i
<= MAX_VALUE
* number
; i
++){
double ratio
= (double) probility
[flag
][i
] / total
;
System
.out
.printf("%d(和) : %e(概率)\n",i
, ratio
);
}
}
public static void main(String
[] args
){
E60Probability
.printProbility(1);
System
.out
.println();
E60Probability
.printProbility(6);
}
}
转载请注明原文地址: https://mac.8miu.com/read-497222.html