3.30编程打卡

7.21(游戏:豆机)

 1 import java.util.*;
 2 public class PlumVase {
 3      public static void plum(int ballNumber,int slotsAccount) {
 4         double probability;
 5         int i,k,position=8;
 6         int one = 1;
 7         int [] array = new int[99];
 8         char[] kk = new char[99];
 9         for (i = 0;i < ballNumber;i ++) {
10             for (k = 0;k < slotsAccount-1;k ++) {
11                 probability = Math.random();
12                 if(probability < 0.5) {
13                     position--;
14                     kk[k] = 'L';
15                 }
16                 else
17                 {
18                     kk[k] = 'R';
19                 }
20             }
21             for (k = 0;k < slotsAccount-1;k ++) {
22                 System.out.print(kk[k]);
23             }
24             System.out.print("
");
25             /*if(one==1) {
26                 position = 0;
27                 one =0;
28             }*/
29             array[position]++;
30             position = 8;
31         }
32         System.out.print("
");
33         for(i=0;i<slotsAccount;i++) {
34             System.out.print(i+" ");
35             for(k=0;k<ballNumber-array[i];k++) {
36                 System.out.print(" ");
37             }
38             for(k=0;k<array[i];k++) {
39                 System.out.print("0");
40             }
41             System.out.print("
");
42         }
43     }
44     
45     public static void main(String[] args) {
46         Scanner input = new Scanner(System.in);
47         System.out.print("Enter the number of balls to drop:");
48         int ballNumber = input.nextInt();
49         System.out.print("Enter the number of balls to drop:");
50         int slotsAccount = input.nextInt();
51         plum(ballNumber,slotsAccount);
52     }
53 
54 }

昨天晚上就开始写,今天才完成,用的逻辑关系比较多。

原文地址:https://www.cnblogs.com/ncoheart/p/8676964.html