Computer Science, asked by dhurkapayal, 3 months ago

wap to input a multidigit number calculate and display the sum of its digit

Answers

Answered by amansarrafas24payxgs
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