Java program to find Sum of Digits

realNameHidden - May 14 '23 - - Dev Community

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
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .