sum of digits in java

Solutions on MaxInterview for sum of digits in java by the best coders in the world

showing results for - "sum of digits in java"
Lana
04 Jun 2016
1import java.util.Scanner;
2public class SumDigit {
3    public static void main(String[] argh){
4        System.out.println("Enter int");
5        Scanner input = new Scanner(System.in);
6        int n = input.nextInt();
7        int sum = 0 ;
8        int i = 0;
9        print( i =Sum_of_digits(sum,n));
10    }
11
12    public static int Sum_of_digits(int sum,int n){
13        if(n<=0)
14            return sum ;
15        sum += n%10;
16        return Sum_of_digits(sum,n/10);
17    }
18
19    public static void  print(int n){
20        System.out.print(n);
21    }
22}
Valentino
25 Apr 2017
1long number, sum;
2Scanner sc = new Scanner(System.in);
3System.out.println("Enter any DIGIT number: ");
4number = sc.nextLong();
5sc.close();
6// For Logic for adding all digits in the given number
7for (sum = 0; number != 0; number /= 10) {
8	sum += number % 10;
9	}
10System.out.println("ForLoop Sum of ALL digits: " + sum);
Alonzo
08 Mar 2019
1import java.io.*;
2public class sd
3{
4  public static void main(String [] args)throws IOException
5  {
6     InputStreamReader hi = new InputStreamReader(System.in);
7        BufferedReader in = new BufferedReader(hi);
8        System.out.println("Enter the number");
9        int num=Integer.parseInt(in.readLine());
10    int sum=0;
11    while(num>=0)
12    {
13      int rem=n;
14      sum+=rem;
15      int quo=n/10;
16      n=quo;
17    }
18    System.out.println(sum);
19  }
20}
Hind
27 Feb 2019
1//To find the sum of even digits in a given Number
2
3    public static int getEvenDigitSum(int number){
4        if(number<0){
5            return -1;
6        }
7        int finalNumber=0;
8        while(number>0){
9           if((number%10)%2==0){
10               finalNumber+=number%10;
11
12           }
13           number=number/10; //takes out last digit to test the next digit
14
15
16        }
17        return finalNumber;
18    }
19//Output: ex:number=12323 -- Ans: 4
Cody
14 Oct 2017
1public class SumNatural {
2
3    public static void main(String[] args) {
4
5        int num = 100, sum = 0;
6
7        for(int i = 1; i <= num; ++i)
8        {
9            // sum = sum + i;
10            sum += i;
11        }
12
13        System.out.println("Sum = " + sum);
14    }
15}
queries leading to this page
sum 3dsum 2b1 javasum in javajava sumjava program to compute the sum of the digits of an integerwrite a java program that sums the digits of an integersum of digits of a number until a single digit is obtained in javahow to find the sum of digits in string javareturn the sum of all the digits that occur in the string or 0 if there are no digits in the given string javajava program than read an integer and calculate the sum of its digits and write the number of each digit of the sum in englishsum of all digits java usin 23 in java to sum number sum of digits in integer javafind sum of digits of a number in javasum of javasum of a 5 digit number in javaadd digits of number in javasum of numerals of a int javajava program to find the sum of all the digits in the inputted numbercode to find sum of digits in javawrite a program that displays the sum of the digits in javajava calculate sum of digitshow to compute sum of 2 numbers in javasum of two numbers in java user inputwrite a method to find out the sum of 3 numbers in javawrite a function that takes an integer and returns the sum of numbers injavasome digits summation of a number in javasum of numbers in an array in javasum of number digits javasum of digits of a number into single digit in javafind sum of numbers in javahow to do sum of digits in javasum of digits an an element javareturn sum of all numbers programs in javasum of digits in ajvajava get sum of digitstake a number and find sum of its digits in java java program to calculate sum of 3 digit numbersum of 2 digit number javasum of digits program in java using for loopjava program for sum of digitssum value in javaproduce sum of numbers javasum of the digits of a number in javahow to sum the digits of a number in javajava sum digits of numbersum of integer number digits javasum of numbers inn javasum of squares of even digits of a number in javacompute sum of all numbers javajava program to find sum of digits in a numbersum of the numebrs is javasum of n numbers in javakeep finding the sum of its digits until the sum becomes a single digit javayou are given a two digit integer n return the sum of its digits javasum of each digit in javamath sum javasum of two number in javasum of integers in javasum of digits of numbers in javasum of 10 numbers in javajava code sumsum of all digits in java using for loophow to sum of digits in javawap to find sum of digits of a given number javafind out whether a number is divisible by the sum of its digits in javato get sum of even digits javajava sum of a numbersum of a number in javae sum of numbers formed by consecutive digits in javajava program to sum of even numbersjava program for adding digits of a numbersum of two numbers in javasum of two number through function in javasum of numbers for loop javasum into single digit in javaget single digit sum for a number javasum of digit javasum of numbers on line javasum digits of a number in javahow to find sum of all digits of a number in javathe sum of digits of the given number in javasum the digits of a number javahow to find the sum of the digits in jacjava digit sumcalculate sum of all numbers present in a string in javasum of odd placed and even place digits in javaprint the sum of the digits of the integer in javadigitsum program in javajava program to find n th number 2f 2f with sum of digits as 9sum of an array in javasum of digits of a string in javajava program to find sum of digits in a stringprint sum of digits in javawrite a java program for sum of numbers upto single digitjava program to find the sum of digits in a stringways to sum javadigitsum program in java with example explanationhow to find a sum of number digits in javasum of prime numbers in javato write a java program to find the sum of digits of a given numbersum of even digits in a number in javawrite a java program and compute the sum of the digits of an integer java code for sum of n numbersfinding the sum of a number in javawrite a java program to sum the digits in an integer 28use 25 and 2f operators 29 e g 1234 3d 10take input from user and sum the digits in javasum of numbers from 0 to n javawhat does it mean to evaluate the sum of numbers in javahow to sum all numbers in javafind sum number in string javacount sum numbers in javaprogram to find sum of natural numbers in javahow to find the sum of digits in javasum of digit in java sum of given integer number in javasum of n number javasum number digits javajava sum of numbersum 28 29 in javajava how to sum each digit of a numbersum of digits in a string in javasum 2b 3d in javahow to get the sum of an intsum of all digits of a number in javasummation loop javajava sum datajava sum of all numbers between two integersjava program to compute the sum of numbers javaadd sum of digits in int javagiven a number a 2c we need to find sum of its digits in javaprogram to calculate sum of n numbers in javaadd all the digits of a number in javasum of digits in java using for loopsum of given number in javasum of digits in javawrite a java program to sum up all the digits of an integer till the sum is a single digit sum of digits of a input number in javajava return sumhow to sum up the digits of an integer in javasum of values in int 5b 5d javahow to get the sum of digits in javaeven digit sum in javaprogram for sum of digits javasum of an array javajava program to find sum of digits of a number until a single digit is obtainedjava find the digit which can sum of a numberjava program to sum of integersfind sum of a number in javayou are given a two digit integer n return the sum of its digits java examplewrite a java program than read an integer and calculate the sum of its digits and write the number of each digit of the sum in english sum up numbers using methods in javasum of numbers in javasum of digits of a number in java using while loopwrite a program that return the sum of even digits of an integer number javahow to find the sum of the digits of a number in javasum of power of digits in javajava program to compute the sum of numbers how to do sum in javajava sum int 5b 5drecution of sum numbers javvaadding sum of integers java summation of digits in javaadd the digits of a number in javahow to sum numbers in loop javadigit sum of an array javajava sum of digits in a numbersum of digits of a number in java using for loopsum digits of a number javasum of a digits javawap to display the sum of digits in a string in javasum code of javasum of digits of number javawords are giving and sum in number javafunction to calculate sum of digits of a number javawrite a program to print the sum of all the digits of a given number in javajava sum of int digitssum of two numbers code in javajava program to calculate sum of n numbersadding number to sum javajava program to compute the sum of the digits of a given numberwrite a java program to input an integer n and print the sum of all its even digits and all its odd digits separately java sum of numbersjava program to find the sum of digits of a given number sum of odd and even digits in a number program in javaprogram to sum of digits of a number in javasum of numbers in a series in javafind sum of the number in javasum 2b 3di in javadigits sum in java mettlthe sum of the even digits in n javainput 2 numbers 2c calculate and display the sum of those numbers in javajava method to compute the sum of the digits in an integerjava sum of digitscalculate sum of all numbers in string javasum of 1 to 100 java progrsmsummation in javanatural number sum program in javahow to find the sum of digits of a number in javanatural numbers sum in javasum of digits program in javasum of digits of a number within a range in javadigit sum in javaadd digits in javadisplay sum of series of numbers in javawrite a java method to compute the sum of the digits in an integerimprove program sum of n natural numbers javasum of digits 28single digit left 29 using javafind sum of all odd numbers in a number javasum of digitss of a number into single digit in javasum the digits in an integerhow to add digits in a number in javasum n numbers in javasum of digit in javajava how to get sum of intsum of nubers javajava for loop sum of numbersprint the sum of digits of number from 1 to n in javahow to find the total of numbers in javahow to sum digits of number until reach one digit in javajava int sumsum code in javaprogram to add digits of a number in javajava program to find the sum of digit entered by the userhow to calculate sum of digits of a number in javahow to sum numbers in javasum of ints in javaadd digits javajava sum if asked digitssum integers in javasum of digits in a string javaadd all numbers of integers in javasum of integer javasum of n numbers without using loop in javacalculate sum of individual numbers javasum java program with source codeadd digits of a number in javainteger sum javahow to find the sum of the digits in javaloops that do sum of different integers in javasum of numbers javaprogram in java to sum numberswhile loop sum javahow to add the digits of a number in javasumdigits 28digits 29 in java6 write a java program to return the sum of the digits present in the given string if there is no digits the sum return is 0 java natural number programjava program to add 2 21 2b5 21 2b8 21java program for sum of digits of given numbersum of digits in an integer javahow to add numbers in for loop javawap to compute sum of digit of a given integer number in java using loophow to sum digits of a number in java 5csum of numbers in javahow to find sum of digits in a string in javasum of 2 numbers in javahow to put a sum in a method and then calling it javacode in java that takes in intergers and adds them together and di1slays the sum with a loopsum of individual digits javasum of digits of a number in java using do while loophow to find the sum of digits of a 3 digits number in javasum of digits of a number on javasum of digits of a number in java streamsum string of numbers in javawrite a java promgrame to compute the sum of the digits in an intigersum of count of digits in a number javasum of two int java write a java program and compute the sum of the digits of an integer input integer 3d62and the sum of the digits is 9java get total digits of an intfind sum of digits java no loophow to find the sum of odd integers javaget number of digits in an integer javasum numbers by for loop in javacalculating sum of digit of a number in java in one lineprogram to calculate sum of n numbers in java using formulaadd all digits on number in javasum the number of digits in a number javajava program to calculate sum of odd and even digits of a numberthe sum of number series in javathe sum of the digits in num with 3 ndigits in javasum of even numbers till n in javajava program to find the number of digits in a numberfind the sum of digits of a number in javajava sum to numberssum of n integers in javasumation code javasum of all digits in an integer javajava sum digits of an integerfind a number which is sum of a number in javajava sum of all numbersjava program for sum of digits in an integerfor loop sum of numbers javacalculate sum of numbers in string javasum of array in java inbuilthow to get sum of digits in javasum digits of number javamethod that determines sum of numbers javasum numbers program javasum all the values of a given array in javahow to find the sum of a number from 1 to that number in javathe java code given below should find the sum of the digits of a number evendigitsum java programyou 27re given an integer n write a program to calculate the sum of all the digits of n javasum of digits at even and odd places in javacreate a program to calculate the sum of numbers from 0 to the number entered in javajava function adds all digits of numbersa program that adds up the first 100 natural numbers using a while loop sum of odd digits in a number in javajava program to find sum of 4 digit numbersum of four digit number in javajava add sum of digitsjava program to calculate the sum of natural numbers 2csum of digit of given number in javaadding the digits of a number in javasum of integers in javahow to make a sum of numbers javasum method in javajava find the sum of int digitssum of its digits in javasum set javaloops that do sum javahow sum of all digits work javasum of number until a single digit in javawrite a java program to count the digit of a number and find out the sum of digit in a numberoutput sum of integers javainteger sum method in javaadd all digits of number in javasum of gretare value javasum of digits of number in javadigit sum javasum of n numbers javajava sum of digits in an integersum of even digits of a number in javajava sum of even numberssum of digits of a five digit number in javajava math sum to numberjava stream sum 28 29sum of all the elements in an integer javasum variables as numbers javasum of two digit number in javajava sum of two numberssum of squares of even digits in javahow to find sum of digits of a number in javassum digits in number javainteger sum javahow to add digit by digit in a number in javarecution of sum numbers javasum of digits of numbers in a series in javaprint sum of digits in java using for loopadd up digits in a integer javasum of digits problem solution in javacode for the sum of digits of nunber in javasum of odd and even digits in a number in javahow to sum digits of an integer in javasum of numbers in java with static voidsum of 2 number in javahow to find the sum of odd integers java streamsum of array in javasum of a and b javajava sum two numberswrite a program to find the sum of till given number in javasystem out println 28 22sum of these numbers 3a 22 2bsumsum of numbers in a string in javainteger sum in javayou are given a two digit integer n return the sum of its digits in javahow to summ in javafind sum of odd integers from 1 to 2001 java streamssum of digits a number javahow to find the sum of one value in javasum of two numbers javasum 2b 3d i javasum of every ith digits in given number javaadd two digits in javaprint sum of all numbers javasum of values inside int 5b 5d javasum numbers javahow to add 2 digits of a number in javasum of natural numbers program in javajava find the integer sum digits is nwrite java program to sum to integersum program in javahow to use the sum function in javasum of digits java 8add the sum from 1 upto a number javahow to enter anyy number of integers and calculate the sum in javaeven digit sum javasum of digits javasum of digits of a number in javafind sum of the digits of number in javasum 28x 29 javawrite a java program to calculatebthe sum of every kth digit in the given numbersum of the digits of a number javasum of digits until single digit in javahow to find the sum of digits by using for loop in javajava integer sumsum of array javahow to do sum of elements in javasum of digits to single digit in javasum the digits in an integer javafind the sum of digits of a given number java codesum 28 29 javahow to sum even numbers in javasum string of numbers javawrite a program that reads a number and shows the sum of its digits in javacompute sum of all digit of number in javasum of natural numbers javaadd digits of a number javasum of two nubers javasum of digit in java formulacompare product at even and odd placesfind numbers that sum up to a number javasum of number in javahow to find the sum of numbers in javahow to find the sum of a number javahow to add digits of a number in javasum of digits using javasum of two numbers using javajava code for sum of digitsjava sum integersthe sum of two numbers in javajava program to find sum of 4 digit number using methodsum of digits in java