码迷,mamicode.com
首页 > 其他好文 > 详细

HW6.21

时间:2016-08-27 19:20:31      阅读:121      评论:0      收藏:0      [点我收藏+]

标签:

技术分享

技术分享

 

 1 import java.util.Scanner;
 2 
 3 public class Solution
 4 {
 5     public static void main(String[] args)
 6     {
 7         Scanner input = new Scanner(System.in);
 8         System.out.print("Enter the number of balls to drop: ");
 9         int numberOfBalls = input.nextInt();
10         System.out.print("Enter the number of slots in the bean machine: ");
11         int numberOfSlots = input.nextInt();
12 
13         input.close();
14 
15         int[] slots = new int[numberOfSlots];
16         int randomNumber;
17         String direction;
18         int count;
19 
20         for(int j = 0; j < numberOfBalls; j++)
21         {
22             count = 0;
23             for(int i = 0; i < numberOfSlots; i++)
24             {    
25                 randomNumber = (int)(Math.random() * 10);
26                 if(randomNumber >= 5)
27                 {
28                     direction = "R";
29                     count++;
30                 }
31                 else
32                     direction = "L";
33                 System.out.print(direction);
34             }
35             slots[count]++;
36             System.out.println();
37         }
38 
39         for(int i = 0; i < numberOfSlots; i++)
40             System.out.print(slots[i] + " ");
41         
42         String[][] outcome = new String[numberOfBalls][numberOfSlots];
43 
44         for(int i = 0; i < numberOfBalls; i++)
45             for(int j = 0; j < numberOfSlots; j++)
46                 outcome[i][j] = " ";
47 
48         for(int i = 0; i < numberOfSlots; i++)
49         {
50             for(int j = numberOfBalls - 1; j > numberOfBalls - slots[i]; j--)
51                 outcome[j][i] = "O";
52         }
53 
54         for(int i = 0; i < numberOfBalls; i++)
55         {
56             for(int j = 0; j < numberOfSlots; j++)
57                 System.out.print(outcome[i][j]);
58             System.out.println();
59         }
60     }
61 }

 

HW6.21

标签:

原文地址:http://www.cnblogs.com/wood-python/p/5813490.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!