import java.util.Scanner;

 public class Solution
 {
     public static void main(String[] args)
     {
         Scanner input = new Scanner(System.in);
         System.out.print("Enter the number of balls to drop: ");
         int numberOfBalls = input.nextInt();
         System.out.print("Enter the number of slots in the bean machine: ");
         int numberOfSlots = input.nextInt();

         input.close();

         int[] slots = new int[numberOfSlots];
         int randomNumber;
         String direction;
         int count;

         for(int j = 0; j < numberOfBalls; j++)
         {
             count = 0;
             for(int i = 0; i < numberOfSlots; i++)
             {
                 randomNumber = (int)(Math.random() * 10);
                 if(randomNumber >= 5)
                 {
                     direction = "R";
                     count++;
                 }
                 else
                     direction = "L";
                 System.out.print(direction);
             }
             slots[count]++;
             System.out.println();
         }

         for(int i = 0; i < numberOfSlots; i++)
             System.out.print(slots[i] + " ");

         String[][] outcome = new String[numberOfBalls][numberOfSlots];

         for(int i = 0; i < numberOfBalls; i++)
             for(int j = 0; j < numberOfSlots; j++)
                 outcome[i][j] = " ";

         for(int i = 0; i < numberOfSlots; i++)
         {
             for(int j = numberOfBalls - 1; j > numberOfBalls - slots[i]; j--)
                 outcome[j][i] = "O";
         }

         for(int i = 0; i < numberOfBalls; i++)
         {
             for(int j = 0; j < numberOfSlots; j++)
                 System.out.print(outcome[i][j]);
             System.out.println();
         }
     }
 }

HW6.21的更多相关文章

  1. 【夯实Mysql基础】MySQL性能优化的21个最佳实践 和 mysql使用索引

    本文地址 分享提纲: 1.为查询缓存优化你的查询 2. EXPLAIN 你的 SELECT 查询 3. 当只要一行数据时使用 LIMIT 1 4. 为搜索字段建索引 5. 在Join表的时候使用相当类 ...

  2. 2-1 Linux 操作系统及常用命令

    根据马哥linux初级视频 2-1.2-2来编辑 1. GUI与CLI GUI: Graphic User Interface CLI: Command Line Interface 注:在Windo ...

  3. Fedora 21 安装 Nvidia 驱动以及失败后的补救方法

    在 Linux 桌面系统下玩了这么久,大部分时间都是使用 Ubuntu,偶尔使用一下 Fedora.我的电脑中安装有多个 Linux 发行版,见这里<在同一个硬盘上安装多个Linux发行版及Fe ...

  4. 在同一个硬盘上安装多个 Linux 发行版及 Fedora 21 、Fedora 22 初体验

    在同一个硬盘上安装多个 Linux 发行版 以前对多个 Linux 发行版的折腾主要是在虚拟机上完成.我的桌面电脑性能比较强大,玩玩虚拟机没啥问题,但是笔记本电脑就不行了.要在我的笔记本电脑上折腾多个 ...

  5. CSharpGL(21)用鼠标拾取、拖拽VBO图元内的点、线或本身

    CSharpGL(21)用鼠标拾取.拖拽VBO图元内的点.线或本身 效果图 以最常见的三角形网格(用GL_TRIANGLES方式进行渲染)为例. 在拾取模式为GeometryType.Point时,你 ...

  6. ABP(现代ASP.NET样板开发框架)系列之21、ABP展现层——Javascript函数库

    点这里进入ABP系列文章总目录 基于DDD的现代ASP.NET开发框架--ABP系列之21.ABP展现层——Javascript函数库 ABP是“ASP.NET Boilerplate Project ...

  7. C#开发微信门户及应用(21)-微信企业号的消息和事件的接收处理及解密

    在上篇随笔<C#开发微信门户及应用(19)-微信企业号的消息发送(文本.图片.文件.语音.视频.图文消息等)>介绍了有关企业号的消息发送,官方特别声明消息是不用加密发送的.但是在回调的服务 ...

  8. 【转】MySQL性能优化的最佳21条经验

    文章转自: http://blog.csdn.net/waferleo/article/details/7179009 今天,数据库的操作越来越成为整个应用的性能瓶颈了,这点对于Web应用尤其明显.关 ...

  9. HTTP 错误 500.21 - Internal Server Error 解决方案

    不久前重新安装了Windows7,在安装了VS2010 开发平台之后,将网站发布到IIS,访问发生如下错误: HTTP 错误 500.21 - Internal Server Error处理程序“Ni ...

随机推荐

  1. Window8 进不了PE如何设置BIOS

    如题,如今进入Win8时代,很多新出的机器都自带了WIN8.但是童鞋们想进PE进行操作的时候,发现进不了. 更改BIOS以下2处设置,即可使用第三方引导安装系统:Boot->Launch CSM ...

  2. IsBadReadPtr|IsBadWritePtr调试崩溃

    遇到一未找到必然出现条件的崩溃,不知道什么时候能触发崩溃,崩溃dump显示,试图访问了非法的内存或者写入了非法的内存 此时如下两个函数就比较有用了: BOOL WINAPI IsBadReadPtr( ...

  3. 关于delete和delete[]

    [精彩] 求问delete和delete[] 的区别??http://www.chinaunix.net/jh/23/311058.html C++告诉我们在回收用 new 分配的单个对象的内存空间的 ...

  4. Kerbose

    http://blog.csdn.net/wulantian/article/details/42418231

  5. linux mysql数据库安装(tar.gz)

    概述 mysql数据库在linux下可以充分发挥威力,mysql数据库越来越受到软件公司的青睐,为什么呢? 免费.跨平台.轻.支持多并发 在北京很多软件公司属于创业型的中.小公司,从节约成本的角度考虑 ...

  6. 【转】VMware设置共享文件夹之后Ubuntu中看不到怎么办?

    一.共享文件夹设置好了,但是在虚拟机中的Ubuntu系统下却看不到,怎么办? 一种可能的原因是系统没有自动挂载,解决办法: 1.安装:               sudo apt-get insta ...

  7. Java API ——StringBuffer类

    1.StringBuffer类概述 1)我们如果对字符串进行拼接操作,每次拼接,都会构建一个新的String对象,既耗时,又浪费空间.而StringBuffer就可以解决这个问题 2)线程安全的可变字 ...

  8. Unable to open c

    1. Unable to open c:\Cadence\PSD_14.2\tools\capture\allegro.cfg for reading. Please correct the abov ...

  9. Lambda表达式 =>(msdn)

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...

  10. poj 1080 Human Gene Functions(dp)

    题目:http://poj.org/problem?id=1080 题意:比较两个基因序列,测定它们的相似度,将两个基因排成直线,如果需要的话插入空格,使基因的长度相等,然后根据那个表格计算出相似度. ...