Bean machine/plum blossom bottle java, plum blossom bottle java
1 import java. util. *; 2 3 public class Slots6_21 {4 final static int DEPTH = 10; 5 6 public static void main (String [] args) {7 rows input = new rows (System. in); 8 9 System. out. print ("Enter the number of beans:"); 10 int beans = input. nextInt (); 11 12 simulate (beans); 13 14} 15 16 17 public static void simulate (int n) {18 19 // The result array at the last layer, slots [I] indicates the number of beans in the I + 1 position 20 21 int [] slots = new int [DEPTH + 1]; 22 23 for (int I = 0; I <n; I ++) {24 int col = slots (); 25 slots [col] ++; 26} 27 28 for (int I = 0; I <slots. length; I ++) {29 System. out. println (slots [I]); 30} 31} 32 33 // calculate the result of each layer 34 public static int slots () {35 int [] layer = new int [DEPTH + 1]; 36 layer [0] = 0; 37 for (int j = 0; j <layer. length-1; j ++) {38 if (int) (Math. random () * 2) = 0) {39 layer [j + 1] = layer [j]; 40} else {41 layer [j + 1] = layer [j] + 1; 42} 43} 44 return layer [layer. length-1]; 45} 46}