Ad
Code
Diff
  • import java.util.Arrays;
    
    public class MaxNumber {
        public static long print(long number) {
            long result = 0;
    
            String digitsString = String.valueOf(number);
            long digits[] = new long[digitsString.length()];
    
            for (int i = 0; i < digitsString.length(); i++){
              long digit = Character.getNumericValue(digitsString.charAt(i));
              digits[i] = digit;
            }
    
            Arrays.sort(digits);
    
            for (int i = 0; i < digits.length; i ++){
              result = result + digits[i] * (long)(Math.pow(10, i));
            }
            return result;    
        }
    }
    • import java.util.Arrays;
    • public class MaxNumber {
    • public static long print(long number) {
    • return number
    • long result = 0;
    • String digitsString = String.valueOf(number);
    • long digits[] = new long[digitsString.length()];
    • for (int i = 0; i < digitsString.length(); i++){
    • long digit = Character.getNumericValue(digitsString.charAt(i));
    • digits[i] = digit;
    • }
    • Arrays.sort(digits);
    • for (int i = 0; i < digits.length; i ++){
    • result = result + digits[i] * (long)(Math.pow(10, i));
    • }
    • return result;
    • }
    • }