aspose file tools*
The moose likes Java in General and the fly likes Addition of digits of a number Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Addition of digits of a number" Watch "Addition of digits of a number" New topic
Author

Addition of digits of a number

sahan thinusha
Greenhorn

Joined: Nov 10, 2012
Posts: 10

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

Joined: Jun 19, 2010
Posts: 825
    
    5

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.


The quieter you are, the more you are able to hear.
Anayonkar Shivalkar
Bartender

Joined: Dec 08, 2010
Posts: 1512
    
    5

Changing the subject line - as the problem is not closely related to arrays.


Regards,
Anayonkar Shivalkar (SCJP, SCWCD, OCMJD, OCEEJBD)
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 11499
    
  16

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.


There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Wesleigh Pieters
Ranch Hand

Joined: Sep 04, 2012
Posts: 81
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

Joined: Nov 16, 2012
Posts: 7
Using scanner? Using var-args? What is the question?
Ivan Franko
Ranch Hand

Joined: May 30, 2011
Posts: 44
to Wesleigh Pieters: cool!
Wesleigh Pieters
Ranch Hand

Joined: Sep 04, 2012
Posts: 81
Ivan Franko wrote:to Wesleigh Pieters: cool!


thanks Ivan
sahan thinusha
Greenhorn

Joined: Nov 10, 2012
Posts: 10

Thanks guys...
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 40052
    
  28
So how did you do it?
Paul Witten
Ranch Hand

Joined: Oct 10, 2012
Posts: 86
Campbell Ritchie wrote:So how did you do it?

He has hidden the details of implementation from you.
Wesleigh Pieters
Ranch Hand

Joined: Sep 04, 2012
Posts: 81
Paul Witten wrote:
Campbell Ritchie wrote:So how did you do it?

He has hidden the details of implementation from you.


 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Addition of digits of a number