write a java program that prompts the user to input and integer and then ouputs both the individual digits of the number and the sum of the digits.
This is what I have but it is not working when I input a negative number. Why? Need help!
import java.util.*;
public class sumDigits {
public static void main(String[] args) {
int aDigit, aNum, theSum=0;
String aStringNum;
char digitAt;
Scanner console = new Scanner(System.in);
System.out.println("Please enter an integer ");
aNum = console.nextInt();
aStringNum = String.valueOf(aNum);
for (int count=0; count < aStringNum.length(); count++) {
digitAt = aStringNum.charAt(count);
aDigit = Character.getNumericValue(digitAt);
theSum += aDigit;
System.out.print(aDigit + " ");
}
System.out.println("The sum is: " + theSum);
}
}