Commit 830c5cae authored by jack.ellis's avatar jack.ellis

initial

parent 7805f22d
Pipeline #223 failed with stages
......@@ -9,24 +9,24 @@ public class AssessmentPartOne {
if (num1<num2)
{
if (num3>num1)
if (num3>num2) // Logical Error: num2 is bigger than num1 so you can't find the biggest number.
{
return num3;
}
else
{
return num1;
return num2;
}
}
else
{
if (num3>num2)
if (num1>num3) // Logical Error: num3 is already calculated in the if statement above so only num1 is left to be ordered so we need to find out where num1 compares to num3.
{
return num3;
return num1;
}
else
{
return num2
return num3; // Syntax Error : ";" was missing.
}
}
}
......@@ -42,10 +42,33 @@ public class AssessmentPartOne {
// You should comment your code explaining what each part does
int sumOfSquares = 0;
return sumOfSquares;
int sumOfSquares = 0; // Declaring answer variable.
if (start <= -1) // Validating start variable to check if it is 0 or over.
{
return -1; // Ends the method and returns -1 as it cannot calculate the result.
}
if (end <= -1) // Validating end variable to check if it is 0 or over.
{
return -1; // Ends the method and returns -1 as it cannot calculate the result.
}
if (end -1 <= start +1) // Validating both start and end variables to see if the start variable is greater than the end variable.
return -1; // Ends the method and returns -1 as it cannot calculate the result.
for (int i = start + 1; i<= end - 1; i++) { // Works out the addition of the range by adding +1 to the start and -1 to the end then adding the current number to a running total within each loop (sumOfSquares).
sumOfSquares = sumOfSquares + i; // Adds the current range value to the end sum.
}
return sumOfSquares; // End of method.
}
}
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