Computer Science, asked by ishtiyak1977khan, 1 month ago

write a Java Program to input a number (not more than 10000) and print total number of digits.​

Answers

Answered by rishi2412010
0

Explanation:

Input : n = 687

Output : 21

Input : n = 12

Output : 3

Recommended: Please solve it on “PRACTICE ” first, before moving on to the solution.

General Algorithm for sum of digits in a given number:

Get the number

Declare a variable to store the sum and set it to 0

Repeat the next two steps till the number is not 0

Get the rightmost digit of the number with help of the remainder ‘%’ operator by dividing it by 10 and add it to sum.

Divide the number by 10 with help of ‘/’ operator to remove the rightmost digit.

Print or return the sum

Similar questions