From b30be927ba80e3a75943ddd81e3db5866bc33324 Mon Sep 17 00:00:00 2001 From: Arti Zirk Date: Mon, 29 Aug 2016 11:16:29 +0300 Subject: [PATCH] Seems to work --- src/Balls.java | 33 +++++++++++++++++++++++++-------- 1 file changed, 25 insertions(+), 8 deletions(-) diff --git a/src/Balls.java b/src/Balls.java index 992e94b..ec445bd 100644 --- a/src/Balls.java +++ b/src/Balls.java @@ -1,14 +1,31 @@ public class Balls { - enum Color {green, red}; + enum Color {green, red}; + + public static void main (String[] param) { + // for debugging + } - public static void main (String[] param) { - // for debugging - } - - public static void reorder (Color[] balls) { - // TODO!!! Your program here - } + 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; + } + } }