public class SumOfDigits
{
public static void main(String[] args)
{
int i = 234;
int sum = 0;
int remainder;
System.out.println("Number Entered: " + i);
while ( i > 0 )
{
remainder= i%10;
sum=sum+remainder;
i=i/10;
}
System.out.println("digits after calculation: " +sum);
}
}
{
public static void main(String[] args)
{
int i = 234;
int sum = 0;
int remainder;
System.out.println("Number Entered: " + i);
while ( i > 0 )
{
remainder= i%10;
sum=sum+remainder;
i=i/10;
}
System.out.println("digits after calculation: " +sum);
}
}
0 comments:
Post a Comment