HW6.21


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的更多相关文章
- 【夯实Mysql基础】MySQL性能优化的21个最佳实践 和 mysql使用索引
本文地址 分享提纲: 1.为查询缓存优化你的查询 2. EXPLAIN 你的 SELECT 查询 3. 当只要一行数据时使用 LIMIT 1 4. 为搜索字段建索引 5. 在Join表的时候使用相当类 ...
- 2-1 Linux 操作系统及常用命令
根据马哥linux初级视频 2-1.2-2来编辑 1. GUI与CLI GUI: Graphic User Interface CLI: Command Line Interface 注:在Windo ...
- Fedora 21 安装 Nvidia 驱动以及失败后的补救方法
在 Linux 桌面系统下玩了这么久,大部分时间都是使用 Ubuntu,偶尔使用一下 Fedora.我的电脑中安装有多个 Linux 发行版,见这里<在同一个硬盘上安装多个Linux发行版及Fe ...
- 在同一个硬盘上安装多个 Linux 发行版及 Fedora 21 、Fedora 22 初体验
在同一个硬盘上安装多个 Linux 发行版 以前对多个 Linux 发行版的折腾主要是在虚拟机上完成.我的桌面电脑性能比较强大,玩玩虚拟机没啥问题,但是笔记本电脑就不行了.要在我的笔记本电脑上折腾多个 ...
- CSharpGL(21)用鼠标拾取、拖拽VBO图元内的点、线或本身
CSharpGL(21)用鼠标拾取.拖拽VBO图元内的点.线或本身 效果图 以最常见的三角形网格(用GL_TRIANGLES方式进行渲染)为例. 在拾取模式为GeometryType.Point时,你 ...
- ABP(现代ASP.NET样板开发框架)系列之21、ABP展现层——Javascript函数库
点这里进入ABP系列文章总目录 基于DDD的现代ASP.NET开发框架--ABP系列之21.ABP展现层——Javascript函数库 ABP是“ASP.NET Boilerplate Project ...
- C#开发微信门户及应用(21)-微信企业号的消息和事件的接收处理及解密
在上篇随笔<C#开发微信门户及应用(19)-微信企业号的消息发送(文本.图片.文件.语音.视频.图文消息等)>介绍了有关企业号的消息发送,官方特别声明消息是不用加密发送的.但是在回调的服务 ...
- 【转】MySQL性能优化的最佳21条经验
文章转自: http://blog.csdn.net/waferleo/article/details/7179009 今天,数据库的操作越来越成为整个应用的性能瓶颈了,这点对于Web应用尤其明显.关 ...
- HTTP 错误 500.21 - Internal Server Error 解决方案
不久前重新安装了Windows7,在安装了VS2010 开发平台之后,将网站发布到IIS,访问发生如下错误: HTTP 错误 500.21 - Internal Server Error处理程序“Ni ...
随机推荐
- properties配置文件中文乱码解决方法
方法1 properties文件的格式一般为: ROOT=http://localhost:8080/BNCAR2/ ROOTPATH=E:/ws2/BNCAR2/rel/ MALL_PARTS_ ...
- 微软的Dll管理方案及其变迁(Side-by-side assembly)
本文简要介绍Side-by-side assembly技术,探讨在插件技术中使用类似方法的可能. 什么是Side-ty-side Assembly Side-by-side assembly是Wind ...
- JAVA面试题:69道Spring面试题和答案
目录 Spring 概述 依赖注入 Spring beans Spring注解 Spring数据访问 Spring面向切面编程(AOP) Spring MVC Spring 概述 1. 什么是spri ...
- 关于DataTables一些小结
最近项目中使用了DataTables,故小结了一下. 导入CSS文件<link rel="stylesheet" href="<%=base %>/js ...
- log4cxx在linux下的编译和使用
[下载] [编译动态库] [使用动态库]
- cmd启动tomcat
1.安装jdk 2.安装tomcat 3.需要配置两个用户环境变量,仅仅配置系统变量没用. a)JAVA_HOME:D:\programing~tools\java~tools\JDK(tm)\jdk ...
- 登陆shell与交互式非登陆shell的区别
登录shell 所谓登录shell,指的是当用户登录系统时所取的那个shell,登录shell属于交互式shell. 登录shell将查找4个不同的启动文件来处理其中的命令. bash shell处理 ...
- Zookeeper基本知识
Zookeeper的Session: (1)客户端和server间采用长连接 (2)连接建立后,server产生session ID(64位)返还给客户端 (3)客户端定期发送ping包来检查和保持和 ...
- 在SQLite中使用索引优化查询速度
在进行多个表联合查询的时候,使用索引可以显著的提高速度,刚才用SQLite做了一下测试. 建立三个表: create table t1 (id integer primary key,num inte ...
- Java 简单登录MVC
构建一个简单的基于MVC模式的JavaWeb 零晨三点半了,刚刚几个兄弟一起出去吼歌,才回来,这应该是我大学第二次去K歌,第一次是大一吧,之后每次兄弟喊我,我都不想去,因为我还是很害怕去KTV,或许是 ...