Custom Sum implementation
Your sum(...) function is fine, given the specification, but there is jut an issue of input validation... what about negative values?

Your current loop condition is input &gt;= 1. This would be better written as input &gt; 0. When you see the &gt;= 1 it makes you wonder if there's a condition that's weird. In this case, there's not.

Further, your code excludes all negative values. What about the sum of -123?

That makes me think that the code should all be looped on the condition input != 0, but that would sum -123 as -6, and not 6.

I was initially tempted to suggest that you have the code:

    input = Math.abs(input);

    int sum = 0;

    while ( input != 0 ) {
        sum += input % 10;
        input = input / 10;
    }

    return sum;


Unfortunately, that has a flaw with Integer.MIN_VALUE (the abs of Integer.MIN_VALUE is.... Integer.MIN_VALUE - a negative number). The net result, is that I considered doing an abs on each digit value inside the loop, but then realized, that all the digits will be negative, so the 'sum' will just be a large negative value, and we can take the absolute of the sum safely, because the sum of the digits will never be large enough to be a problem...

Thus, the solution I would recommend is:

public static int sumSumAbs(int input) {

    int sum = 0;

    while ( input != 0 ) {
        sum += input % 10;
        input = input / 10;
    }

    return Math.abs(sum);
}


That code (adjusted to fit in to my Eclipse IDE with a static method call, and different name), will work for any input value, of any sign, and ignore the sign in the result.