ImLittleNugget
ImLittleNugget ImLittleNugget
  • 01-04-2021
  • Engineering
contestada

i need some help with this


Java programing

i need some help with this Java programing class=

Respuesta :

zayeb27
zayeb27 zayeb27
  • 01-04-2021

def digit_sum(number):

 sumOfDigits = 0

 while number > 0:

     sumOfDigits += number % 10

     number = number // 10

 return sumOfDigits

or you can use,

In [2]: digit_sum(10)

Out[2]: 1

In [3]: digit_sum(434)

Out[3]: 11

or you can use,

digits = "12345678901234567890"

digit_sum = sum(map(int, digits))

print("The equation is: ", '+'.join(digits))

print("The sum is:", digit_sum)

Have a great day <3

Answer Link

Otras preguntas

When a photo is reduced or enlarged, its length to width ratio usually remains the same. Aurelia wants to enlarge a 4-inch by 6-inch photo so that it has a widt
Explain why 5(10)/5(2) equals 5(8)
How tall is a stack of ten pennies in centimeters?
what the words below have in common. a. minuteman b. Loyalist c. Patriot
Sam has 1,300 dimes. Anna has 1/10 the number of dimes Sam has. How many dimes does Anna have?
what is a list of events in the order in which they took place
examples of diversity in relation to beliefs
Which of the following is considered a hypothesis as opposed to an observation
what did the demand for enslaved workers increase as southern colonies grew
what did the demand for enslaved workers increase as southern colonies grew