Searching...
Sunday, 11 December 2016

Program to find out sum of digits

07:21


Main program

package com.vinod.test;


/**
 *@authorvinodkariyathungalkumaran
 *
 */
public class FindSumOfDigits {
    public static void main(String[] args) {
        {
            int sum, d;
            int a = 111;
            sum = 0;
            for (int i = 1; i <= 10; i++) {
                d = a % 10;
                a = a / 10;
                sum = sum + d;
            }
            System.out.println("Sum of Digit =" + sum);
        }
    }

}

Ouput

Sum of Digit =3


0 comments: