class Main{ String g(int n, int depth){ // Recursive method with 2 int parameters & String return-type int remainder = n % depth; // The current recursive remainder if(depth < n){ // If we aren't done with the number yet: int nextDepth = depth * 10; // Go to the next depth (of the power of 10) int nextN = n - remainder; // Remove the remainder from the input `n` // Do a recursive call with these next `n` and `depth` String resultRecursiveCall = g(nextN, nextDepth); if(remainder != 0){ // If the remainder was not 0: // Append a " + " and this remainder to the result resultRecursiveCall += " + " + remainder; } return resultRecursiveCall; // And return the result } else{ // Else: return Integer.toString(n); // Simply return input `n` as result } } String f(int n){ // Second method so we can accept just integer `n` return g(n, 1); // Which will call the recursive call with parameters `n` and 1 } public static void main(String[] a){ Main m = new Main(); m.test(9); m.test(10); m.test(12); m.test(101); m.test(123); m.test(1024); m.test(70304); } void test(int input){ System.out.println(f(input)); } }