You need to sign in or sign up before continuing.×
import java.util.Arrays;
public class MaxNumber {
public static long print(long number) {
return number
}
}
import static org.junit.Assert.assertEquals;
import org.junit.Test;
import java.util.Random;
public class MaxNumberTest {
@Test
public void testFour() {
assertEquals(4, MaxNumber.print(4));
}
@Test
public void testTwelve() {
assertEquals(21, MaxNumber.print(12));
}
@Test
public void testOneHundred() {
assertEquals(110, MaxNumber.print(101));
}
@Test
public void testHuge1() {
assertEquals(754000000000000000L, MaxNumber.print(400000005000007000L));
}
@Test
public void testHuge2() {
assertEquals(988777666444322200L, MaxNumber.print(307778062924466824L));
}
}
import java.util.Arrays;
public class MaxNumber {
public static long print(long number) {
return number
}
}
import static org.junit.Assert.assertEquals;
import org.junit.Test;
import java.util.Random;
public class MaxNumberTest {
@Test
public void testFour() {
assertEquals(4, MaxNumber.print(4));
}
@Test
public void testTwelve() {
assertEquals(21, MaxNumber.print(12));
}
@Test
public void testOneHundred() {
assertEquals(110, MaxNumber.print(101));
}
@Test
public void testHuge1() {
assertEquals(754000000000000000L, MaxNumber.print(400000005000007000L));
}
@Test
public void testHuge2() {
assertEquals(988777666444322200L, MaxNumber.print(307778062924466824L));
}
}
import java.util.Arrays;
public class MaxNumber {
public static long print(long number) {
return number
}
}
import static org.junit.Assert.assertEquals;
import org.junit.Test;
import java.util.Random;
public class MaxNumberTest {
@Test
public void testFour() {
assertEquals(4, MaxNumber.print(4));
}
@Test
public void testTwelve() {
assertEquals(21, MaxNumber.print(12));
}
@Test
public void testOneHundred() {
assertEquals(110, MaxNumber.print(101));
}
@Test
public void testHuge1() {
assertEquals(754000000000000000L, MaxNumber.print(400000005000007000L));
}
@Test
public void testHuge2() {
assertEquals(988777666444322200L, MaxNumber.print(307778062924466824L));
}
}
import java.util.Arrays;
public class MaxNumber {
public static long print(long number) {
return number
}
}
import static org.junit.Assert.assertEquals;
import org.junit.Test;
import java.util.Random;
public class MaxNumberTest {
@Test
public void testFour() {
assertEquals(4, MaxNumber.print(4));
}
@Test
public void testTwelve() {
assertEquals(21, MaxNumber.print(12));
}
@Test
public void testOneHundred() {
assertEquals(110, MaxNumber.print(101));
}
@Test
public void testHuge1() {
assertEquals(754000000000000000L, MaxNumber.print(400000005000007000L));
}
@Test
public void testHuge2() {
assertEquals(988777666444322200L, MaxNumber.print(307778062924466824L));
}
}
import java.util.Arrays; public class MaxNumber { public static long print(long number) { return number; } }
- 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;- return number;
- }
- }
Given a number, write a program to find a maximum number that can be formed using all of the digits of this number.
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 number
for (int i = digits.length - 1; i >= 0; i--) {
int digit = Character.getNumericValue(digits[i]);
maxNumber = maxNumber * 10 + digit;
}
return maxNumber;
}
}
import static org.junit.Assert.assertEquals;
import org.junit.Test;
import java.util.Random;
public class MaxNumberTest {
@Test
public void testFour() {
assertEquals(4, MaxNumber.print(4));
}
@Test
public void testTwelve() {
assertEquals(21, MaxNumber.print(12));
}
@Test
public void testOneHundred() {
assertEquals(110, MaxNumber.print(101));
}
@Test
public void testHuge1() {
assertEquals(754000000000000000L, MaxNumber.print(400000005000007000L));
}
@Test
public void testHuge2() {
assertEquals(988777666444322200L, MaxNumber.print(307778062924466824L));
}
}