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

Answer on this one please: the coastline of the United States is 12,383 miles long.canada's coastline is 113,211 miles longer than the coastline of United State
Is .634 rational number
what is the answer to 4/7 x - 3 =6
what number is 100,000,000 more than 5,438,724,022?
If 2x+ 3y = 55 and 4x= y+ 47, find x − y. Can you please explain with some details?
Estimate 144,898. Please write that in estimation form
Greg bought 2 boxes of balloons he used half of them to decorate his yard he used 40 to decorate his porch he used the rest inside his house how many balloons d
How do you convert 1.16 in to a fraction
Round 681,542 to the nearest hundred thousand
There are 15 lottery tickets available. Roy know that 6 of them are winning. If Roy picks one ticket at random what is the probability that it will be a winning