Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
A
Assessment part 2
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
joel.guest
Assessment part 2
Commits
e63ad7ad
Commit
e63ad7ad
authored
Nov 05, 2018
by
joel.guest
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
initial
parent
7805f22d
Pipeline
#367
failed with stages
Changes
1
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
34 additions
and
6 deletions
+34
-6
AssessmentPartOne.java
src/AssessmentPartOne.java
+34
-6
No files found.
src/AssessmentPartOne.java
View file @
e63ad7ad
...
...
@@ -7,17 +7,21 @@ public class AssessmentPartOne {
// Debug this method so it passes the unit test.
// Add comments beside any changes you make
if
(
num1
<
num2
)
if
(
num1
>
num2
)
// LOGICAL ERROR (changed the sign so that num1 is greater then num2)
{
if
(
num3
>
num1
)
{
return
num3
;
//now if num3 is bigger than num1 it means it is the biggest
}
else
{
return
num1
;
//if num3 is not bigger than num1 then num1 is the biggest
}
}
//if num1 is not greater than num2 it means num2 or num3 is bigger meaning it moves straight to this else
else
{
if
(
num3
>
num2
)
...
...
@@ -26,13 +30,13 @@ public class AssessmentPartOne {
}
else
{
return
num2
return
num2
;
// SYNTAX ERROR (semi-colon is added after num2)
}
}
}
public
int
sumNumbersBetween
(
int
start
,
int
end
)
{
public
int
sumNumbersBetween
(
int
start
,
int
end
)
{
// 02 - Adding Across A Range
// Complete this method so that it adds together all
// the integers between start and end, but not including
...
...
@@ -44,8 +48,32 @@ public class AssessmentPartOne {
int
sumOfSquares
=
0
;
//DEFAULT
//if the start value is less than 0 the programme will return -1 as it only deals with positive integers
if
(
start
<
0
){
return
-
1
;
}
//if the end value is less than 0 the programme will return -1 as it only deals with positive integers
if
(
end
<
0
){
return
-
1
;
}
//if the start value is less then the end value the programme will return -1
//it does this by making sure start +1 is grater than end-1
if
(
end
-
1
<=
start
+
1
){
return
-
1
;
}
//if none of the default tests are through it runs an else with the for loop that holds the code that adds the values within the range
else
{
// this for loop loops between all the values within the range of start and end excluding the values of start and end themselves
for
(
int
i
=
start
+
1
;
i
<=
end
-
1
;
i
++)
{
//adds all the integers between start and end
sumOfSquares
=
sumOfSquares
+
i
;
}
}
return
sumOfSquares
;
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment