DEV Community

Cover image for Java program to find Sum of Digits
realNameHidden
realNameHidden

Posted on

Java program to find Sum of Digits

For Explanation watch the video

code ::

import java.util.*;
import java.lang.*;
class Demo{
    public static void main(String[] args){
        int n = 555;
        int sum = 0;
        while(n>0){
            int r = n%10;
            sum = sum + r;
            n = n/10;
        }
        System.out.println(sum);
    }
}
Enter fullscreen mode Exit fullscreen mode

Top comments (0)