encontrar numero maximo
import java.util.Arrays; public class MaxNumber { public static long print(long number) { // Place your logic String numberStr = Long.toString(number); char[] digitos = numberStr.toCharArray(); Arrays.sort(digitos); String numeroMaximoStr = new StringBuilder(new String(digitos)).reverse().toString(); return Long.parseLong(numeroMaximoStr); } }
- import java.util.Arrays;
- public class MaxNumber {
- public static long print(long number) {
char[] digits = Long.toString(number).toCharArray();Arrays.sort(digits);long maxNumber = 0;// Traverse the sorted array in reverse order// to get the maximum numberfor (int i = digits.length - 1; i >= 0; i--) {int digit = Character.getNumericValue(digits[i]);maxNumber = maxNumber * 10 + digit;}return maxNumber;- // Place your logic
- String numberStr = Long.toString(number);
- char[] digitos = numberStr.toCharArray();
- Arrays.sort(digitos);
- String numeroMaximoStr = new StringBuilder(new String(digitos)).reverse().toString();
- return Long.parseLong(numeroMaximoStr);
- }
- }