Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Addition of digits of a number

 
sahan thinusha
Greenhorn
Posts: 10
Android Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello code ranch i have following problem please help me.
01). user enters a number(for example : 4365)how to add digits of that number(example :4+3+6+5) and print the total(example : print 18)
 
Kemal Sokolovic
Bartender
Posts: 825
5
Java Python Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And your idea for getting a solution is...? This is NotACodeMill, nobody's going to provide a solution for you. You need to ShowSomeEffort, take your best shot and try something that makes sense to you, so we can all discuss it further.
 
Anayonkar Shivalkar
Bartender
Posts: 1557
5
Eclipse IDE Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Changing the subject line - as the problem is not closely related to arrays.
 
fred rosenberger
lowercase baba
Bartender
Posts: 12127
30
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You need to start by breaking down the problem into individual, discrete parts. Then, write the code for ONE part at a time and thoroughly test before starting the next.

For example, you can write code that breaks apart the individual digits in a number completely separately from the part that takes input from the user.
 
Wesleigh Pieters
Ranch Hand
Posts: 81
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
there are a few ways this could be done, Strings toCharArray() method, the charAt method inside a loop and probably split as well. obviously parse to an int and then addition.
 
Adriano Ribeiro
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Using scanner? Using var-args? What is the question?
 
Ivan Franko
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
to Wesleigh Pieters: cool!
 
Wesleigh Pieters
Ranch Hand
Posts: 81
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ivan Franko wrote:to Wesleigh Pieters: cool!


thanks Ivan
 
sahan thinusha
Greenhorn
Posts: 10
Android Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks guys...
 
Campbell Ritchie
Sheriff
Pie
Posts: 48972
60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So how did you do it?
 
Paul Witten
Ranch Hand
Posts: 86
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Campbell Ritchie wrote:So how did you do it?

He has hidden the details of implementation from you.
 
Wesleigh Pieters
Ranch Hand
Posts: 81
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Paul Witten wrote:
Campbell Ritchie wrote:So how did you do it?

He has hidden the details of implementation from you.


 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic