DO WHILE LOOP - Java

Do … while:   It is an another exit control loop,all the statement will execute until the condition become false.
Syntax:
            do
            {
                        Statements;
            }
            while(condition);

WRITE A PROGRAM TO FIND THE SUM OF DIGITS OF GIVEN NUMBER.

class Sum
{
public static void main(String args[])
{
int n=123,b,c=0;
do
{
b=n%10;
n=n/10;
c=c+b;
}
while(n>0);
System.out.println("Sum of digits: "+c);
}
}

For
Online Classes

Contact Us: 9885348743