View Single Post
  #7 (permalink)  
Old 11-23-2009, 08:56 PM
Singing Boyo Singing Boyo is offline
Senior Member
 
Join Date: Mar 2009
Posts: 392
Rep Power: 2
Singing Boyo is on a distinguished road
Default
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!
Reply With Quote