import java.util.Arrays; public class MaxNumber { public static long print(long number) { // Convert the number to a string String numStr = Long.toString(number); // Convert the string to an array of characters char[] digits = numStr.toCharArray(); // Sort the array of digits in non-ascending order Arrays.sort(digits); StringBuilder sb = new StringBuilder(new String(digits)); sb.reverse(); // Convert the sorted array of digits back to a long long maxNumber = Long.parseLong(sb.toString()); return maxNumber; } }
- import java.util.Arrays;
- public class MaxNumber {
- public static long print(long number) {
return number- // Convert the number to a string
- String numStr = Long.toString(number);
- // Convert the string to an array of characters
- char[] digits = numStr.toCharArray();
- // Sort the array of digits in non-ascending order
- Arrays.sort(digits);
- StringBuilder sb = new StringBuilder(new String(digits));
- sb.reverse();
- // Convert the sorted array of digits back to a long
- long maxNumber = Long.parseLong(sb.toString());
- return maxNumber;
- }
- }