I'm assuming that by trace you mean that you need to trace the progress of the computation. In that case, change your for loop to this:
|
Code:
|
public static int sumRange(int start, int end){ //this should be the parameters
int sum = 0
if (end < start)
system.out.println ("ERROR: Invalid Range");//println, not printIn (L not I)
else
for (int num = start; num < = end; num++){
//brackets because you need to print sum, which means the loop will have more
//than one statement
sum + = num;
//code to print the sum here (same idea as printing the error message)
}
return sum;
} |
I'll leave you to figure out the printing code.
__________________
If the above doesn't make sense to you, ignore it, but remember it - might be useful!
And if you just randomly taught yourself to program, well... you're just like me!