i have a problem in a java program. :
"accept a number and print the sum of digits."
can anyone help me out???
vAshunk
0
Newbie Poster
Recommended Answers
Jump to PostBreak the problem down into smaller, easier to manage steps.
- Get user input
- Calculate the sum of the number(s) entered
- Print resultShow us that you have put some effort in by showing us what you have so far and we will help you from there, …
Jump to PostIt is simple but you also have to think of user mistakes.
Ex. user inputs 1 2 3456 asdf 234 as the input string. The letters and spaces are unwanted characters.
You will have to parse the input correctly, never assume that the user will enter what you …
Jump to PostSeems about right, although I wouldn't put the user input in the sumOfDigits method. I would keep user interaction in the main function of your app. Your sum method should not have to "worry" about asking the user for input it should just process the value handed to it. Anyone …
All 11 Replies
majestic0110
187
Nearly a Posting Virtuoso
gonzi.p12
0
Newbie Poster
smoothe19
-1
Junior Poster in Training
skfroi
0
Newbie Poster
vAshunk
0
Newbie Poster
vAshunk
0
Newbie Poster
skfroi
0
Newbie Poster
kdkanishka
0
Newbie Poster
skfroi
0
Newbie Poster
vAshunk
0
Newbie Poster
vAshunk
0
Newbie Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.