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

Calculate Compound Interest in JavaScript

How to make simple bill maker by using python tkinter

Admin Login Page Using HTML and CSS