Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
Programming 01 Task 1-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
christopher.spray
Programming 01 Task 1-2
Commits
1afe1997
Commit
1afe1997
authored
Jan 07, 2019
by
spray
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
OG upload
parent
7805f22d
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
22 additions
and
8 deletions
+22
-8
AssessmentPartOne.java
src/AssessmentPartOne.java
+22
-8
No files found.
src/AssessmentPartOne.java
View file @
1afe1997
...
...
@@ -7,26 +7,26 @@ 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
)
//if num1 is bigger than num2 (changed < to >
)
{
if
(
num3
>
num1
)
if
(
num3
>
num1
)
//and if num3 is bigger than num1
{
return
num3
;
return
num3
;
//num3 is the biggest, so return that
}
else
{
return
num1
;
return
num1
;
//if num1 is bigger than num3, num1 is the biggest so return that
}
}
else
{
if
(
num3
>
num2
)
if
(
num3
>
num2
)
{
return
num3
;
return
num3
;
//if num1 is bigger than num2, and num3 is bigger than num2, return num3
}
else
{
return
num2
return
num2
;
//else return num2 because it is larger
}
}
}
...
...
@@ -42,9 +42,23 @@ public class AssessmentPartOne {
// You should comment your code explaining what each part does
int
sumOfSquares
=
0
;
int
sumOfSquares
=
0
;
//initialise sumOfSquares
if
(
start
<
0
||
end
<
0
)
{
return
-
1
;
//because the program can only deal with 0/positive ints, if it is 0 or lower, return -1
}
else
if
(
start
>
end
)
{
return
-
1
;
//if the start is bigger than the end, return -1 as it can't calculate the result
}
else
if
(
end
-
start
<=
1
)
{
return
-
1
;
//if the end minus the start is 1 or lower, return -1 as it can't calculate the result
}
for
(
int
i
=
start
+
1
;
i
<
end
;
i
++)
{
//when start+1 is lower than the end
sumOfSquares
+=
i
;
//sumOfSquares = itself + 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