@@ -9,10 +9,17 @@ public class AssessmentPartOne {
...
@@ -9,10 +9,17 @@ public class AssessmentPartOne {
if(num1<num2)
if(num1<num2)
{
{
if(num3>num1)
if(num3>num1&&num3>num2)// added a check if num3 is also bigger than num2
{
{
returnnum3;
returnnum3;
}
}
elseif(num2>num3)
{
returnnum2;
}// added an else if checking if num2 is bigger than num3
// no need to check if bigger than num1 as won't enter if statement if not
else
else
{
{
returnnum1;
returnnum1;
...
@@ -20,13 +27,17 @@ public class AssessmentPartOne {
...
@@ -20,13 +27,17 @@ public class AssessmentPartOne {
}
}
else
else
{
{
if(num3>num2)
if(num3>num2&&num3>num1)// added a check if num3 is also bigger than num1
{
{
returnnum3;
returnnum3;
}
}
elseif(num2>num3)
{
returnnum2;// added a semicolon
}// added an else if to check if num2 is bigger than num3
else
else
{
{
returnnum2
returnnum1;
}
}
}
}
}
}
...
@@ -43,9 +54,22 @@ public class AssessmentPartOne {
...
@@ -43,9 +54,22 @@ public class AssessmentPartOne {
// You should comment your code explaining what each part does
// You should comment your code explaining what each part does
intsumOfSquares=0;
intsumOfSquares=0;
if((start<end)&&(start+1<end)){// checks if the starting number is smaller than the ending number, and if there are numbers between the start and end number
for(inti=start+1;i<end;i++){// goes through each number between, but not including, the start and end numbers
if(sumOfSquares>=0){// check that the sum isn't smaller than 0 currently
sumOfSquares=sumOfSquares+i;// adds the current number to the sum
}
else{
sumOfSquares=-1;// sets the sum to -1 if the sum is smaller than 0
}
}
}
else{
sumOfSquares=-1;// sets the sum to -1 if it cannot calculate the result