Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Calculating the sum of numbers in a user defined range.

 
WeiJie Lim
Ranch Hand
Posts: 92
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


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
Posts: 1051
5
Chrome Eclipse IDE Hibernate
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 92
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic