If you are reading from the user, its already a String. No need to make it an Integer that you are not going to use.
With the string, you can just use a for loop to iterate through each character
|
Code:
|
long sum = 0;
for (int i=0; i < arg.length(); i++) {
String c = arg.substring(i,i);
sum += Integer.valueOf(c);
} |
This may not work, I typed it into the forum, not a compiler, but it should get you going. Debug on your own, its part of learning