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 = …


This content originally appeared on DEV Community and was authored by NJ

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);
    }
}


This content originally appeared on DEV Community and was authored by NJ


Print Share Comment Cite Upload Translate Updates
APA

NJ | Sciencx (2023-05-14T09:58:24+00:00) Java program to find Sum of Digits. Retrieved from https://www.scien.cx/2023/05/14/java-program-to-find-sum-of-digits/

MLA
" » Java program to find Sum of Digits." NJ | Sciencx - Sunday May 14, 2023, https://www.scien.cx/2023/05/14/java-program-to-find-sum-of-digits/
HARVARD
NJ | Sciencx Sunday May 14, 2023 » Java program to find Sum of Digits., viewed ,<https://www.scien.cx/2023/05/14/java-program-to-find-sum-of-digits/>
VANCOUVER
NJ | Sciencx - » Java program to find Sum of Digits. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2023/05/14/java-program-to-find-sum-of-digits/
CHICAGO
" » Java program to find Sum of Digits." NJ | Sciencx - Accessed . https://www.scien.cx/2023/05/14/java-program-to-find-sum-of-digits/
IEEE
" » Java program to find Sum of Digits." NJ | Sciencx [Online]. Available: https://www.scien.cx/2023/05/14/java-program-to-find-sum-of-digits/. [Accessed: ]
rf:citation
» Java program to find Sum of Digits | NJ | Sciencx | https://www.scien.cx/2023/05/14/java-program-to-find-sum-of-digits/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.