Ad
Code
Diff
  • import java.util.Arrays;
    
    public class MaxNumber {
        public static long print(long number) {
          String numberStr = Long.toString(number);
          char[] digits = numberStr.toCharArray();
          Arrays.sort(digits);
          for (int i = 0; i < digits.length / 2; i++) {
                char temp = digits[i];
                digits[i] = digits[digits.length - i - 1];
                digits[digits.length - i - 1] = temp;
            }
          String maxNumberStr = new String(digits);
           number =  Long.parseLong(maxNumberStr);
            return number;
        }
    }
    • import java.util.Arrays;
    • public class MaxNumber {
    • public static long print(long number) {
    • return number
    • String numberStr = Long.toString(number);
    • char[] digits = numberStr.toCharArray();
    • Arrays.sort(digits);
    • for (int i = 0; i < digits.length / 2; i++) {
    • char temp = digits[i];
    • digits[i] = digits[digits.length - i - 1];
    • digits[digits.length - i - 1] = temp;
    • }
    • String maxNumberStr = new String(digits);
    • number = Long.parseLong(maxNumberStr);
    • return number;
    • }
    • }