wap to input a multidigit number calculate and display the sum of its digit
Answers
Answered by
0
Answer:
import java.util.*;
class Sum_Of_Digits
{
public void main ()
{
Scanner sc = new Scanner (System.in);
System.out.println("Enter a number: ");
int n = sc.nextInt();
int rem,sum = 0;
for(int i = n;i > 0;i++)
{
rem = i%10;
sum+=rem;
}
System.out.println("Sum of digits: " + sum);
}
}
I hope you find it useful... If you have any query do comment, I will try to solve it...
Similar questions