So this is my code so far.
public int getsum (int n){ int num = 23456; int total = 0; while (num != 0) { total += num
Short, recursive and does the job:
int getsum(int n) { return n == 0 ? 0 : n % 10 + getsum(n/10); }