import java.util.Arrays; public class MaxNumber { public static long print(long number) { String numberString = Long.toString(number); char[] digits = numberString.toCharArray(); Arrays.sort(digits); StringBuilder maxNumberStr = new StringBuilder(new String(digits)); maxNumberStr.reverse(); long maxNumber = Long.parseLong(maxNumberStr.toString()); number = maxNumber; return number; } }
- import java.util.Arrays;
- public class MaxNumber {
- public static long print(long number) {
return number- String numberString = Long.toString(number);
- char[] digits = numberString.toCharArray();
- Arrays.sort(digits);
- StringBuilder maxNumberStr = new StringBuilder(new String(digits));
- maxNumberStr.reverse();
- long maxNumber = Long.parseLong(maxNumberStr.toString());
- number = maxNumber;
- return number;
- }
- }