import java.util.Arrays; import java.util.Collections; public class MaxNumber { public static long print(long number) { String numberString = Long.toString(number); Character [] digitos = new Character[numberString.length()]; for(int i = 0; i < numberString.length(); i++){ digitos[i] = numberString.charAt(i); } Arrays.sort(digitos, Collections.reverseOrder()); StringBuilder maxNumStr = new StringBuilder(); for (Character digit : digitos){ maxNumStr.append(digit); } return Long.parseLong(maxNumStr.toString()); } }
- import java.util.Arrays;
- import java.util.Collections;
- public class MaxNumber {
- public static long print(long number) {
return number- String numberString = Long.toString(number);
- Character [] digitos = new Character[numberString.length()];
- for(int i = 0; i < numberString.length(); i++){
- digitos[i] = numberString.charAt(i);
- }
- Arrays.sort(digitos, Collections.reverseOrder());
- StringBuilder maxNumStr = new StringBuilder();
- for (Character digit : digitos){
- maxNumStr.append(digit);
- }
- return Long.parseLong(maxNumStr.toString());
- }
- }