import java.io.*;
class SumOfDigits
{
public static void main(String args[])
{
BufferedReader bf=new BufferedReader(new InputStreamReader(System.in));
int a=0,b=0;
try
{
System.out.println("enter the number");
a=Integer.parseInt(bf.readLine());
}
catch(Exception e)
{
e.printStackTrace();
}
int sum=0;
while(a>0)
{
b=a%10;
sum=sum+b;
a=a/10;
}
System.out.println("Sum of digits = "+sum);
}
}
class SumOfDigits
{
public static void main(String args[])
{
BufferedReader bf=new BufferedReader(new InputStreamReader(System.in));
int a=0,b=0;
try
{
System.out.println("enter the number");
a=Integer.parseInt(bf.readLine());
}
catch(Exception e)
{
e.printStackTrace();
}
int sum=0;
while(a>0)
{
b=a%10;
sum=sum+b;
a=a/10;
}
System.out.println("Sum of digits = "+sum);
}
}
Comments
Post a Comment