I want to read a number as a String, and split its characters to an integer array, and find the sum of it's digits by looping through that integers array.

This is my code so far:

```
public static void main(String[] args) {
    Scanner S = new Scanner(System.in);
    String Number = S.next();
    int counterEnd = Number.length();
    int sum = 0 ;

    for ( int i = 0 ; i < counterEnd ; i++) {
         sum += sum + (Number.charAt(i));
    }

    System.out.println(sum);
}

```

Unfortunately, this code prints the sum of ASCII not the digits.
['https://Stackoverflow.com/questions/28630360', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/3301836/']
You can subtract the `'0'` character (i.e. `'1' - '0'` is `49 - 48` = `1`):

```
sum += Number.charAt(i) - '0';

```
You could, has @August suggested, substract the character `'0'` to obtain the numeric value of the character (I find this approach kind of hackish). Or you can use [`Character.getNumericValue`](http://docs.oracle.com/javase/7/docs/api/java/lang/Character.html#getNumericValue(char)) to achieve this:

```
sum += Character.getNumericValue(Number.charAt(i)); //note it's sum += theDigit; not sum += sum + theDigit

```

You might also want to look at the enhanced for loop, as you basically don't need the index here:

```
for(char c : Number.toCharArray()) {
    sum += Character.getNumericValue(c);
}

```

As of Java 8 you could also do it like this:

```
int sum = Number.chars().map(Character::getNumericValue).sum();

```

It basically gets a `Stream` of the characters in the `String`, map each character to its corresponding numeric value and sum them.