zoukankan      html  css  js  c++  java
  • 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 }

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

  • 相关阅读:
    windows p12(pfx)个人证书安装过程
    OpenSSL库验证PKCS7签名
    Crypto库实现PKCS7签名与签名验证
    windows 系统中打开一个数字证书所经历的过程
    DBA不可不知的操作系统内核参数
    MySQL大表优化方案
    深入浅出Cache
    Git Stash用法
    Git服务器搭建全过程分步详解
    laravel 5.1 性能优化对比
  • 原文地址:https://www.cnblogs.com/ncoheart/p/8676964.html
Copyright © 2011-2022 走看看