Reverse a number and find the sum of its digits using do while loop in java programming
it is a java programs to Reverse Reverse a Number and find the Sum of its Digits Using do-while Loop.
Enter any integer as an input. After that we use operations like modulus and division to reverse a number
and find sum of its digits along with the help of do-while loop.
you can find the source code of java program
to Reverse a Number and find the Sum of its Digits Using do-while Loop. The Java program is successfully
compiled and run on a Windows system. The program output is also shown below.
import java.util.*;
public class usedowhileloop
{
public static void main (String args[])
{
int n,a,m=0,sum=0;
Scanner s = new Scanner(System.in);
System.out.print("Enter any number:");
n=s.nextInt();
do
{
a=n%10;
m=m*10+a;
sum=sum+a;
n=n/10;
while(n>0)
System.out.println("Reverse:"+m);
System.out.println("Sum of digits:"+sum);
}
}
0 comments:
Post a Comment