Add comments

This commit is contained in:
Arti Zirk 2016-08-29 11:22:05 +03:00
parent b30be927ba
commit 22e75573a9

View File

@ -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;
}