用MAP进行转换

import java.util.Scanner;
import java.util.List;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Map;
import java.util.HashMap;
import java.util.Collections;

// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        // 注意 hasNext 和 hasNextLine 的区别
        while (in.hasNextLine()) { // 注意 while 处理多个 case
            String[] strArry = in.nextLine().split(" ");
            System.out.println(combin(strArry));
        }
    }
    public static String combin(String[] strArry) {
        Map<Character, Character> map = new HashMap<>();
        map.put('0', '0'); map.put('1', '8'); map.put('2', '4');
        map.put('3', 'C'); map.put('4', '2'); map.put('5', 'A');
        map.put('6', '6'); map.put('7', 'E'); map.put('8', '1');
        map.put('9', '9'); map.put('A', '5'); map.put('B', 'D');
        map.put('C', '3'); map.put('D', 'B');map.put('E', '7');
        map.put('F', 'F'); map.put('a', '5'); map.put('b', 'D');
        map.put('c', '3'); map.put('d', 'B');map.put('e', '7');
        map.put('f', 'F');
        String strll = strArry[0] + strArry[1];
        List<Character> list1 = new ArrayList<>();
        List<Character> list2 = new ArrayList<>();
        for (int i = 0; i < strll.length(); i++) {
            if (i % 2 == 0) {
                list1.add(strll.charAt(i));
            } else {
                list2.add(strll.charAt(i));
            }
        }
        Collections.sort(list1);
        Collections.sort(list2);
        StringBuffer sb = new StringBuffer();
        int length = Math.min(list1.size(), list2.size());
        for (int i = 0; i < length; i++) {
            char tempList1 = list1.get(i);
            sb.append(map.getOrDefault(tempList1, tempList1));
            char tempList2 = list2.get(i);
            sb.append(map.getOrDefault(tempList2, tempList2));
        }
        if (list1.size() > list2.size()) {
            sb.append(map.getOrDefault(list1.get(list1.size() - 1), list1.get(list1.size() - 1)));
        } else if (list1.size() < list2.size()) {
            sb.append(map.getOrDefault(list2.get(list2.size() - 1), list2.get(list2.size() - 1)));
        }
        return sb.toString();
    }
}