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

How have human factors contributed to climate change, and what evidence supports these factors? How have nonhuman factors contributed to climate change, and wha
the answer to the equation
¿Cómo se llama IMB en Costa Rica? IBM Costa Rica Correo Central GBM
Which of the following is NOT a type of synovial joint in the human body? A. pivot B. stirrup C. hinge D. gliding
Which of the following is not a skill-related component of physical fitness? Body Conposition Power Balance Reaction Time
A line passes through the point (–7, 5) and has a slope of 1/5. Which is another point that the line passes through?
Which forms of government are citizens able to show dissent
how many triangles can be constructed with angles measuring 90 60 60 A. None B. One C. More than one
Geography is a ____ field of study that is concerned with ____.
3a-2b\c-1 a=9 b=3 c=2