wap to read a number from a user and print there sum of digits.
//wap to read a number from a user and print there sum of digits.
import java.util.Scanner;
class assingment4
{
public static void main(String[] arg)
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter number : ");
int n=sc.nextInt();
int sum=0;
while(n>0)
{
int rem=n%10;
n=n/10;
sum=sum+rem;
}
System.out.println("Sum of digits ="+sum);
}
}
Comments
Post a Comment