a program in java to accept 3 digit number and find sum of its digits
sample input=647
sample out put=17(6+4+7)
Answers
Answered by
6
Answer:
import java.util.*;
class sum
{
public static void main ()
{
Scanner sc=newScanner(System.in);
int n,i,d=0,s=0;
System.out.println("Enter a three digit number:");
n=sc.nextInt();
for(i=n ; i>0 ; i/=10)
{
d=i%10;
s=s+d;
}
System.out.println("Sum of digits="+s);
}
}
Similar questions