diff --git a/src/Balls.java b/src/Balls.java index ec445bd..13cd0df 100644 --- a/src/Balls.java +++ b/src/Balls.java @@ -10,6 +10,7 @@ public class Balls { public static void reorder (Color[] balls) { int redBallCount = 0; + // count how many red balls there is for (int i = 0; i < balls.length; i++) { if (balls[i] == Color.red) { redBallCount++; @@ -17,9 +18,14 @@ public class Balls { } + // If all balls are red or green then just return if (redBallCount == balls.length) { return; + } else if (redBallCount == 0) { + return; } + + // replace the contents of the array with new colors that are in correct order for (int i = 0; i < redBallCount; i++) { balls[i] = Color.red; }