1 ImportJava.util.*;2 3 Public classslots6_21 {4 Final Static intDEPTH = 10;5 6 Public Static voidMain (string[] args) {7Scanner input =NewScanner (system.in);8 9System.out.print ("Enter The number of beans:");Ten intBeans =input.nextint (); One A simulate (beans); - - } the - - Public Static voidSimulate (intN) { - + //The result array of the last layer, Slots[i] indicates the number of beans in i+1 position - + int[] Slots =New int[Depth+1]; A at for(inti = 0; I < n; i++) { - intCol =slots (); -Slots[col] + +; - } - - for(inti = 0; i < slots.length; i++) { in System.out.println (Slots[i]); - } to } + - //calculate results for each layer the Public Static intslots () { * int[] Layer =New int[Depth+1]; $Layer[0] = 0;Panax Notoginseng for(intj = 0; J < Layer.length-1; J + +) { - if((int) (Math.random () * 2) = = 0) { theLAYER[J+1] =Layer[j]; +}Else { ALAYER[J+1] = Layer[j] + 1; the } + } - returnLayer[layer.length-1]; $ } $}
Bean Machine/Plum bottle Java