Commit 2dfed994 authored by nouman.ashraf's avatar nouman.ashraf

1

parent 7805f22d
Pipeline #571 canceled with stages
...@@ -9,24 +9,24 @@ public class AssessmentPartOne { ...@@ -9,24 +9,24 @@ public class AssessmentPartOne {
if (num1<num2) if (num1<num2)
{ {
if (num3>num1) if (num3>num2)//replace num1 with num2;
{ {
return num3; return num3;
} }
else else
{ {
return num1; return num2;//replace num1 with num2;
} }
} }
else else
{ {
if (num3>num2) if (num3>num1)//replaced num2 with num1;
{ {
return num3; return num3;
} }
else else
{ {
return num2 return num1;//added colon here and replace num2 with num1;
} }
} }
} }
...@@ -43,7 +43,33 @@ public class AssessmentPartOne { ...@@ -43,7 +43,33 @@ 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;
int a=(end-start)-1; //I used "a" for the setting length of Loop below => (Like i<a)
int b=(end-start); //I used "b" for checking difference which help me that difference should be greater then 1.
int sum=0; //I used "sum" for storing value that you can see in a loop.
if(start >= 0 & end >= 0 & b>1) //These are the conditions If "start" and "end" are greater then equal to "0" and "b" should greater then "1" then move forwared otherwise move on else statement.
{
for(int i=0;i<a;i++) //Loop
{
sum=sum+(start+1); //This step adding 1 in start's number and store in sum.
start++; //It will increment in "start" number,for moving to the next number.
sumOfSquares=sum; //Now I stored value of "sum" in "sumOfSquare" for return.
}
return sumOfSquares;
}
else //If anything is not possible
{
sumOfSquares=-1; //it return -1 when it cannot calculate the result
}
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