Skip to content
Snippets Groups Projects
Commit ebccc64f authored by Goik Martin's avatar Goik Martin
Browse files

Intermediate state

parent b4b34547
No related branches found
No related tags found
No related merge requests found
......@@ -41,11 +41,29 @@ public class App {
}
/**
* Format a sum of an array of integer values according to the following
* rules:
* 1. Avoiding zeroes
* 2. Trying to start a sum with a non-negative value
* 3. Representing single values without equal sign.
*
* Examples:
* {1,7,-4} --> "1+7-4=4"
* {-1,7,3} --> "7-1+3=9"
* {5} --> "4"
* {} --> "0"
* {0,0,0} --> "0"
* {1,0,4,0,0,5} --> "1+4+5=10"
*
* @param values The set of integer values to be represented as a sum
* @return The formatted string.
*/
static public String prettifyOutput(final int[] values) {
final int [] reducedCopy = new int[values.length];
// Copy all but zeroes
// Copy all values but zeroes
int currentIndex = 0;
for (final int value : values) {
if (0 != value) {
......@@ -54,7 +72,9 @@ public class App {
}
// check for first value being negative
if (1 < reducedCopy.length && reducedCopy[0] < 0) {
for (int i = 1; i < reducedCopy.length && reducedCopy[i] < 0; i++);
}
return null;//TODO
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment