假期结束,忙里偷闲写代码!写的有点混乱··不过结果还行吧_(:з」∠)_

 1 package qqqqqqqqqqqqq;
 2 
 3 import java.util.Arrays;
 4 import java.util.Scanner;
 5 
 6 public class Qqqq {
 7 
 8 /*豆机
 9  * 提示用户输入槽数和球数
10  * 显示球的路径和落球最后的图示    
11  */
12 
13     
14     public static void main(String[] args) {
15     Scanner input=new Scanner(System.in);        
16         System.out.println("输入球数量:");
17         int ballNum=input.nextInt();
18         System.out.println("输入槽数量:");
19         int slotNum=input.nextInt();
20         direction(slotNum,ballNum);        
21     }
22     
23     //循环输出左右,num1=槽数,num2=球数
24     public static void direction(int num1,int num2){
25         int l=0;
26         int[] ballimages=new int[num1];//储存每个槽的落球数
27         System.out.println("球的路径:");
28         while(l<num2){
29             System.out.print("\n"+(l+1)+"号球:");
30             int n=0;
31         for(int i=0;i<num1-1;i++){
32             //随机数      大于5为左,反之为右
33             double f=Math.random();
34             char d;
35             if(f>0.5)
36                  {d='L';}
37             else
38                  {d='R';n++;}
39             System.out.print(d);    
40         }            
41         ballimages[n]+=1;
42         l++;
43         }
44         //System.out.println(Arrays.toString(ballimages));//方便自己查看数组的结果,可以注释掉
45         System.out.println("\n");
46         System.out.println("球落下图:");
47         ball(ballimages);                
48     }
49     
50   //利用ballimage打印球图示
51     public static void ball(int []nums){
52         int max=0;
53         for(int num:nums){
54             if(num>max){
55                 max=num;
56             }
57         }
58         int i=0;
59         int j=max;
60         while(i<max){for(int num:nums){
61             
62             
63                 if(num>=j)
64                 System.out.print("0");
65                 else
66                 System.out.print(" ");            
67             }
68         i++;
69         j--;
70         System.out.print("\r");
71         }
72     }
73     
74 }

 

posted on 2017-08-03 13:16  Akinero  阅读(136)  评论(0编辑  收藏  举报