Add comments
This commit is contained in:
parent
b30be927ba
commit
22e75573a9
@ -10,6 +10,7 @@ public class Balls {
|
|||||||
public static void reorder (Color[] balls) {
|
public static void reorder (Color[] balls) {
|
||||||
int redBallCount = 0;
|
int redBallCount = 0;
|
||||||
|
|
||||||
|
// count how many red balls there is
|
||||||
for (int i = 0; i < balls.length; i++) {
|
for (int i = 0; i < balls.length; i++) {
|
||||||
if (balls[i] == Color.red) {
|
if (balls[i] == Color.red) {
|
||||||
redBallCount++;
|
redBallCount++;
|
||||||
@ -17,9 +18,14 @@ public class Balls {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// If all balls are red or green then just return
|
||||||
if (redBallCount == balls.length) {
|
if (redBallCount == balls.length) {
|
||||||
return;
|
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++) {
|
for (int i = 0; i < redBallCount; i++) {
|
||||||
balls[i] = Color.red;
|
balls[i] = Color.red;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user