@@ -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.
{
returnnum3;
}
else
{
returnnum1;
returnnum2;
}
}
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.
{
returnnum3;
returnnum1;
}
else
{
returnnum2
returnnum3;// Syntax Error : ";" was missing.
}
}
}
...
...
@@ -42,10 +42,33 @@ public class AssessmentPartOne {
// You should comment your code explaining what each part does
intsumOfSquares=0;
returnsumOfSquares;
intsumOfSquares=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(inti=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.