Commit 930b5890 authored by Benco's avatar Benco

Task1 Complete.

parent 2fe07381
...@@ -42,10 +42,27 @@ public class AssessmentPartOne { ...@@ -42,10 +42,27 @@ 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; int sumOfSquares = 0; //Defines and initialises the total value.
if (start < end-1) { //Validates whether there are any numbers between the start and end and whether the start value is less than the end value.
if (!(start < 0) || (end < 0)) { //Validates that both the start and end values are not negative numbers.
return sumOfSquares; //Adds up all values from the start to the end exclusive of themselves.
for(int i=start+1;i<end;i++) {
sumOfSquares = sumOfSquares + i;
}
}
else { //If the start and end value is a negative number.
sumOfSquares = -1; //Sets the sumOfSquares to -1; indicating that the calculation cannot be carried out.
}
}
else { //If there are no values between the start and end or if the start value is less than the end value.
sumOfSquares = -1; //Sets the sumOfSquares to -1; indicating that the calculation cannot be carried out.
}
return sumOfSquares; //Returns the value.
} }
} }
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