import java.util.Scanner; public class beanMachine { public static void main(String[] args) { Scanner input = new Scanner(System.in); System.out.print("Enter the number of balls to drop: "); int numBalls = input.nextInt(); System.out.print("Enter the number of slots in the bean machine: "); int numSlots = input.nextInt(); int[] slots = new int[numSlots]; char direction; int numRight; for (int i = 0; i < numBalls; i++) { numRight = 0; for (int j = 0; j < numSlots - 1; j++) { direction = leftOrRight(); if (direction == 'R') numRight++; System.out.print(direction); } slots[numRight]++; System.out.println(); } for (int i = numBalls; i > 0; i--) { for (int j = 0; j < numSlots; j++) { if (slots[j] >= i) { System.out.print(0); } else System.out.print(" "); } System.out.println(); } } public static char leftOrRight() { int random = (int) (Math.random() * 10000000) % 2; if (random == 0) return 'L'; else return 'R'; } }