Write a program to find sum of digit in java

 Write a program to find sum of digit in java


public class SumOfDigit
{
    public static void main(String args[]){
        int num=253,sum=0;
        while(num!=0){
            sum += num%10;
            num=num/10;
        
        }
        System.out.println("Sum of digit: "+sum);
    }
}

Output

Sum of digit: 10

Comments

Popular posts from this blog

Make a GST Calculator using HTML and JavaScript

How to make simple bill maker by using python tkinter

Write a program to find the sum of 1/2+4/3+5/6+8/7+9/10 using loop in java