• Post Reply Bookmark Topic Watch Topic
  • New Topic

Sum of numbers  RSS feed

 
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I have a string, Eg. abc12de12, I need to add the numbers from the string, (say)1+2+1+2 = 6

Any idea??


-raka
 
Bartender
Posts: 3271
82
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Explain how you would do it if you had to solve the problem with just a pen and paper.
 
Ranch Hand
Posts: 1163
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Of course we all have ideas. But the important thing is you should get the idea. Start by studying the Scanner class.
 
Bartender
Posts: 10575
66
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
raka oscr wrote:I have a string, Eg. abc12de12, I need to add the numbers from the string, (say)1+2+1+2 = 6...

And just to add to the other good advice, you need to explain your requirements accurately.

What you are doing is adding digits, not "numbers"; otherwise, your answer would be 12+12 = 24.

Winston
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!