Java Number Sum sumDigits(String number)

Here you can find the source of sumDigits(String number)

Description

Sums the digits of a natural number represented as a String.

License

Apache License

Parameter

Parameter Description
number a parameter

Declaration

public static int sumDigits(String number) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

public class Main {
    /**//from www .  ja  va2  s . co  m
     * Sums the digits of a natural number represented as a String.
     * 
     * @param number
     * @return
     */
    public static int sumDigits(String number) {
        return number.chars().map(aChar -> Character.getNumericValue(aChar)).sum();
        /*
         * int sum = 0; for (int i = 0; i < number.length(); i++) { sum +=
         * Integer.valueOf(number.substring(i, i + 1)); }
         * 
         * return sum;
         */
    }
}

Related

  1. sum_quad(long max)
  2. sum_quad_endrec(long max)
  3. sumaMesFull(String sF, int n)
  4. sumAsDouble(Iterable values)
  5. SumDiffErr(float Term1Err, float Term2Err)
  6. sumDivisors(int n)
  7. sumError(long samples, long count, double m2, double mean)
  8. sumFirstIntegers(final long i)
  9. sumFirstN(long n)