aspose file tools*
The moose likes Beginning Java and the fly likes Calculating the sum of numbers in a user defined range. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Calculating the sum of numbers in a user defined range." Watch "Calculating the sum of numbers in a user defined range." New topic
Author

Calculating the sum of numbers in a user defined range.

WeiJie Lim
Ranch Hand

Joined: Sep 05, 2012
Posts: 91


I have the error of " not a statement " for the line in which I applied the formula for summation. The formula given is (n-m+1)(n+m) /2 , where m is the starting number and n is the last number.
James Boswell
Bartender

Joined: Nov 09, 2011
Posts: 1031
    
    5

For multiplication, you need to use the * character.

So, for a variable x, multiplying it by 2 would be 2 * x, not 2x.
WeiJie Lim
Ranch Hand

Joined: Sep 05, 2012
Posts: 91
James Boswell wrote:For multiplication, you need to use the * character.

So, for a variable x, multiplying it by 2 would be 2 * x, not 2x.


Oh gosh, I totally missed the * after trying to debug my code for quite some time..

Thanks a million.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Calculating the sum of numbers in a user defined range.