Sort these integers for me ...
By name ...
import java.util.Arrays;
import java.util.Comparator;
public class Dinglemouse {
private static final String[] tens = { "", "ten", "twenty", "thirty", "forty", "fifty", "sixty", "seventy",
"eighty", "ninety" };
private static final String[] nums = { "", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine",
"ten", "eleven", "twelve", "thirteen", "fourteen", "fifteen", "sixteen", "seventeen", "eighteen",
"nineteen" };
public static String convert(int n) {
if (n == 0)
return "zero";
String result;
if (n % 100 < 20) {
result = nums[n % 100];
n /= 100;
} else {
result = nums[n % 10];
n /= 10;
result = tens[n % 10] + result;
n /= 10;
}
if (n == 0)
return result;
return nums[n] + " hundred" + result;
}
public static int[] sort(final int array[]) {
return Arrays.stream(array).boxed()
.sorted(Comparator.comparing(Dinglemouse::convert)).map(String::valueOf)
.mapToInt(Integer::valueOf).toArray();
}
}