Bean machine/plum blossom bottle java, plum blossom bottle java

Source: Internet
Author: User

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}

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.