class
sumdigit
{
public
static void main(String as[])
{
System.out.println("sum
of digits program");
int
n=12345;
int
d,sum=0;
while(n>0)
{
d=n%10;
n=n/10;
sum=sum+d;
}
System.out.println("sum:
"+sum);
}
}
Output:
sum of digits program
sum:
15
class
sumdigit
{
public
static void main(String as[])
{
System.out.println("sum
of digits program");
int
n=12345;
int
d,sum=0;
while(n>0)
{
d=n%10;
n=n/10;
sum=sum+d;
}
System.out.println("sum:
"+sum);
}
}
Output:
sum of digits program
sum:
15
0 Comments
Post a Comment