home1/src/Balls.java

32 lines
645 B
Java

public class Balls {
enum Color {green, red};
public static void main (String[] param) {
// for debugging
}
public static void reorder (Color[] balls) {
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;
}
}
}