Commit d72bfe36 authored by nathan.joynes's avatar nathan.joynes

initial

parent 7805f22d
Pipeline #222 failed with stages
...@@ -7,7 +7,10 @@ public class AssessmentPartOne { ...@@ -7,7 +7,10 @@ public class AssessmentPartOne {
// Debug this method so it passes the unit test. // Debug this method so it passes the unit test.
// Add comments beside any changes you make // Add comments beside any changes you make
if (num1<num2)
// I have changed the logical error in the first line to correct the initial error and make the code run correctly.
// In this case the sign was the opposite way round.
if (num1>num2)
{ {
if (num3>num1) if (num3>num1)
{ {
...@@ -25,8 +28,9 @@ public class AssessmentPartOne { ...@@ -25,8 +28,9 @@ public class AssessmentPartOne {
return num3; return num3;
} }
else else
// Syntax error: I have added in the missing ; to the following line.
{ {
return num2 return num2;
} }
} }
} }
...@@ -42,9 +46,25 @@ public class AssessmentPartOne { ...@@ -42,9 +46,25 @@ public class AssessmentPartOne {
// You should comment your code explaining what each part does // You should comment your code explaining what each part does
int sumOfSquares = 0; // Here I am declaring the variable of int sumOfSquares at the beginning of my method.
int sumOfSquares = 0;
// I have validated my start variable to ensure that it starts at 0 or above.
if ( start <= -1) return -1;
// I have also done the same here with the 'end' variable to ensure that this is also greater than or equal to 0.
if (end <= -1) return -1;
// Here I am checking that the start variable is bigger than the end variable. This throws -1 of the start is greater than end.
if (end -1 <= start +1) return -1;
// This for loop allows me to grab the range between the start end variables excluding both the start and end value.
for (int i = start +1; i<= end -1; i++)
//This adds the ith value to the running total.
sumOfSquares = sumOfSquares +i;
// Method end.
return sumOfSquares; return sumOfSquares;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment