Seems to work
This commit is contained in:
parent
9b58a62f9e
commit
b30be927ba
@ -8,7 +8,24 @@ public class Balls {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void reorder (Color[] balls) {
|
public static void reorder (Color[] balls) {
|
||||||
// TODO!!! Your program here
|
int redBallCount = 0;
|
||||||
|
|
||||||
|
for (int i = 0; i < balls.length; i++) {
|
||||||
|
if (balls[i] == Color.red) {
|
||||||
|
redBallCount++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if (redBallCount == balls.length) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
for (int i = 0; i < redBallCount; i++) {
|
||||||
|
balls[i] = Color.red;
|
||||||
|
}
|
||||||
|
for (int i = redBallCount; i < balls.length; i++) {
|
||||||
|
balls[i] = Color.green;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user