I really need a hand, I have to write the java for the following; the user enters a number and the integers of that number are added, for example I enter "234" and the programs produces "2+3+4=9"
Really grateful for any help received.
Welcome to the Java Programming Forums
The professional, friendly Java community. 21,500 members and growing!
The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.
>> REGISTER NOW TO START POSTING
Members have full access to the forums. Advertisements are removed for registered users.
I really need a hand, I have to write the java for the following; the user enters a number and the integers of that number are added, for example I enter "234" and the programs produces "2+3+4=9"
Really grateful for any help received.
Look at using these two operators: / and %
One to get a digit, the other to shift the remaining digits to the right.
If you don't understand my answer, don't ignore it, ask a question.
Cheers,
Would you have any idea how it would look??
Try experimenting with some simple statements that use those operators and print out the results.
If you don't understand my answer, don't ignore it, ask a question.
does it print the result as "2+3+4=9" or it will add all the numbers producing 9 as a result?
i will assume you are looking for the former output. first you have to separate all numbers and add them to an array, for this you may use the toCharArray() method of String class. After this create a loop that will traverse your array, convert them into integer since your array is in char datatype. Then add them to variable and print the result.