Well ... you could take advantage of the character set order, which has '0' then '1', '2', ... '9' in that order.
So subtracting '0' from each character will give you the value:
import java.util.*;
public class Main {
public static void main (String args[]) {
String no = "1234";
char ch[] = no.toCharArray ();
int sum = 0;
for (int i = 0; i < 4; i++) {
sum = sum + (int) (ch[i] - '0');
}
System.out.println (sum);
}
}
But ... I'd strongly suggest you validate your inputs by checking that they are digits first!