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 }

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

  • 相关阅读:
    获取app下载链接
    查找文件的路径
    回忆基础:制作plist文件
    Ping++中的AlipaySDK和AlicloudUTDID冲突解决方案
    CocoaPods常用操作命令
    自签名配置HTTPS
    Instruments10 分析某个类中方法的执行时间
    iOS KVC/KVO
    iOS 系统架构及常用框架
    LINQ to SQLite完美解决方案
  • 原文地址:https://www.cnblogs.com/ncoheart/p/8676964.html
Copyright © 2011-2022 走看看