Java

Program to find sum of Digits

public class SumOfDigits 
{   
    public static void main(String[] args)   
    {   
        int i = 234;   
   int sum = 0;   
   int remainder;
        
    
        System.out.println("Number Entered: " + i);   

        while ( i > 0 )  
        {  
        remainder= i%10;   
 sum=sum+remainder;
         i=i/10;   
         }
         
            System.out.println("digits after calculation: " +sum);  
        }   
    }  

Related Posts

language_img
Java

Factorial Program

Oct 4, 2013

language_img
Java

Methods

Oct 4, 2013

language_img
Java

Inner Classes

Oct 3, 2013

Table Of Contents

;