Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class Exercise6_21 {
- public static void main(String[] args) {
- Scanner in = new Scanner(System.in);
- System.out.print("Enter the number of balls to drop: ");
- int balls = in.nextInt();
- System.out.print("Enter the number of slots in the bean machine: ");
- int slotNum = in.nextInt();
- int[] slots = new int[slotNum];
- for (int i = 0; i < balls; i++) {
- int count = slotNum - 1;
- int rights = 0;
- String path = "";
- while (count > 0) {
- double choice = Math.floor(Math.random() * 2);
- if (choice == 0) {
- path += "L";
- } else {
- path += "R";
- rights++;
- }
- count--;
- }
- slots[rights]++;
- System.out.println(path);
- }
- while (balls > 0) {
- String ballPlace = "";
- for (int i = 0; i < slots.length; i++) {
- if (slots[i] == balls) {
- ballPlace += "O";
- slots[i]--;
- } else {
- ballPlace += " ";
- }
- }
- balls--;
- System.out.println(ballPlace);
- }
- }
- }
Add Comment
Please, Sign In to add comment