I'm having some problems writing a method that will take two integers and add up the sum of the integers and all the numbers between them. Ex. the int are 3 and 7, the method does 3+4+5+6+7 and returns 25.
What I have so far is:
CODE
public int sum(int num1, int num2)
{
if(num1<num2)
for (int sum = num1; num1 <= num2; num1++)
{
sum += num1;
return sum;
}
if (num2>num1)
for (int sum = num2; num2 <= num1; num2++)
{
sum += num2;
return sum;
}
}
I still have to write a portion showing what happens when num1 and num2 are equal, but... when I try to compile what I have so far I get the following error:
C:\Documents and Settings\Brad\Desktop\CSE\Geek.java:75: missing return statement
}
^
When I comment that section of my code out it compiles, so I'm sure that's where the problem is but I can't see what return I'm missing (I'm terribly new at java). Am I even close?
Any help would be appreciated.