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 }

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

  • 相关阅读:
    java中Calendar类里面的月份是月份数减一。
    hdu oj
    存在重复元素
    杨辉三角
    删除链表的倒数第n个结点
    相交链表
    环形链表 II
    环形链表
    至少是其他数字两倍的最大数
    寻找数组的中心索引
  • 原文地址:https://www.cnblogs.com/ncoheart/p/8676964.html
Copyright © 2011-2022 走看看