import java.util.Arrays; import java.util.Comparator; public class MaxNumber { public static long print(long number) { String maxNumber = Arrays.stream(String.valueOf(number).split("")) .sorted((s1, s2) -> s2.compareTo(s1)) .reduce("", (s1, s2) -> s1 + s2); number = Long.parseLong(maxNumber); return number; } }
- import java.util.Arrays;
- import java.util.Comparator;
- public class MaxNumber {
- public static long print(long number) {
return number- String maxNumber = Arrays.stream(String.valueOf(number).split(""))
- .sorted((s1, s2) -> s2.compareTo(s1))
- .reduce("", (s1, s2) -> s1 + s2);
- number = Long.parseLong(maxNumber);
- return number;
- }
- }