Professional Documents
Culture Documents
Add Digits of Number in Java
Add Digits of Number in Java
To add digits of any number in Java programming, you have to ask to the user to enter the
number to add their digits and display the summation of digits of that number.
Following Java program ask to the user to enter the number to add their digits and will
display the addition result :
import java.util.Scanner;
temp = num;
while(num>0)
{
rem = num%10;
sum = sum+rem;
num = num/10;
}
When the above Java Program is compile and executed, it will produce the following output: