版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
import java.util.*;
public class beanmachine {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);//用户输入
System.out.print("Enter the number of balls to drop:");
int x=sc.nextInt();
Scanner s=new Scanner(System.in);
System.out.print("Enter the number of slots in the beanmachine:");
int y=s.nextInt();//实现逻辑
int [] slots=new int[y];
Random r=new Random();
for(int j=1;j<=x;j++) {
int n=0;
for(int i=1;i<=7;i++) {
boolean b=r.nextBoolean();
if(b==true) {
char a='R';
n++;
System.out.print(a);
}else {
char c='L';
System.out.print(c);
}
}
slots[n]++;
System.out.println();
}
int max=getmax(slots);//打印图形
System.out.println(Arrays.toString(slots));
System.out.println(max);
for(int n=max;n>0;n--) {
for(int k=0;k<slots.length;k++) {
if(n<=slots[k]) {
System.out.print("0 ");
}else {
System.out.print(" ");
}
}
System.out.println();
}
System.out.println("0 1 2 3 4 5 6 7");
}
public static int getmax(int []slots) {
int max=slots[0];
for(int i=1;i<=slots.length-1;i++) {
if(slots[i]>max) {
max=slots[i];
}
}
return max;
}
}