public static void max(int x) { int temp = x; while (true) { int index = (int)Math.log10(temp); if (index < 0) { return; } int highDigit = (int) (Math.pow(10, index)); int highNumber = temp / highDigit; if (9 > highNumber) { x = x + highDigit * (9 - highNumber); System.out.println(x); return; } temp = temp - highDigit * highNumber; } }