Don't instantiate a new Scanner object for every input, youDon't instantiate a new Scanner object for every input
You only ever need 1 Scanner.
Format Strings
You can use System.out.printf to print formatted strings, such as:
System.out.printf("You are dropping %d balls into %d slots\n", numberOfBalls, numberOfSlots);
Put comments above the line of code, not in the same line.Put comments above the line of code, not in the same line.
// like this
someCode();
someCode(); // NOT like this
Use java naming standards,Use java naming standards
private & method scoped variables should begin with a lower case letter. The formatting in stackexchange gives you a hint, it thinks Slots is a class since it begins with an uppercase:
// should be int slots[].
int Slots[] = new int[numberOfSlots];
Give names that make sense
eachBallPath doesn't really make sense as a method name. printEachBallPath would make more sense.
Same printBallPaths would make even more sense.
Or if you'd like, calculateBallPaths, and have the method return an Array that can be printed elsewhere.
Same for ballInSlot and pathTaken. Maybe getBallInSlot and getPathTaken. If you don't like using get for methods other than getters, I'd suggest calculatePathTaken & calculateBallInSlot.
However you should also add documentation to these methods since it's very unclear from reading the return statements & the method names.
Regarding the code below:Regarding the code below:
always use curly braces even when the code is 1 length long.
It's upsetting when instructors teach students to this, it's more upsetting that your instructor actually encourages it (As you mentioned in the comments.
A good explanationA good explanation:
Skimping on braces might save you a few keystrokes the first time, but
the next coder who comes along, adds something to your else clause
without noticing the block is missing braces is going to be in for a
lot of pain.
Write your code for other people.
use else if or else whenever it makes sense to do so
You can use shorthand +=, -=, *=, /= etc, instead of variable = + variable etc.
if (random < 0.5)
path = path + "L";
if (random >= 0.5)
path = path + "R";