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.
Here is the source code of the 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.
public class Use_Do_While
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();
a = n % 10;
m = m * 10 + a;
sum = sum + a;
n = n / 10;
while( n > 0);
System.out.println("Sum of digits:"+sum);
$ javac Use_Do_While.java $ java Use_Do_While Enter any number:456 Reverse:654 Sum of digits:15
Sanfoundry Global Education & Learning Series – 1000 Java Programs.