• 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 }

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

  • 相关阅读:
    Spark的精简安装步骤---陈楠心血总结
    关于Hadoop的集群环境下虚拟机采用NAT方式连不上网的解决
    size_t总结
    POJ 1852 Ants
    Digital Roots 1013
    1350. Primary Arithmetic
    Word Reversal
    POJ 2876 Cantoring Along
    逆序数的求法
    C++ 中cin
  • 原文地址:https://www.cnblogs.com/ncoheart/p/8676964.html
Copyright © 2020-2023  润新知