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.
Printable View
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.
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.
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.