Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
G
GoikLectures
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Deploy
Releases
Container Registry
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Goik Martin
GoikLectures
Commits
ebccc64f
Commit
ebccc64f
authored
9 years ago
by
Goik Martin
Browse files
Options
Downloads
Patches
Plain Diff
Intermediate state
parent
b4b34547
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
P/Sd1/Console_sum/src/main/java/de/hdm_stuttgart/mi/sda1/console_sum/App.java
+22
-2
22 additions, 2 deletions
...c/main/java/de/hdm_stuttgart/mi/sda1/console_sum/App.java
with
22 additions
and
2 deletions
P/Sd1/Console_sum/src/main/java/de/hdm_stuttgart/mi/sda1/console_sum/App.java
+
22
−
2
View file @
ebccc64f
...
...
@@ -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
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment