Question: I need to sum all digits in a given string. So for I've got this 

```
public static void main(String[] args) {

    Scanner odczyt = new Scanner(System.in);
    System.out.println("Input string");
    String ciag = odczyt.nextLine();

    int suma = 0;

    for (int i = 0; i < ciag.length(); i++) {
        if (Character.isDigit(ciag.charAt(i))) {
            suma += ciag.charAt(i);
        }
    } 
    System.out.println(suma);
}

```

When I input:

> 
> "Ala got 3 apples and 1 orange"
> 
> 
> 

the output is 100 instead of 4. What should I change to make it count only digits?

Answer: 
The problem occurs here:

```
suma += ciag.charAt(i);

```

you're adding the character code rather than the digit itself.

change it to this:

```
suma += Integer.parseInt(ciag.charAt(i)+"");

```
That is because you are adding the ascii code of numbers. Just subtract '0' from the char number as shown below:

suma += ciag.charAt(i)-'0';