基础知识学习:https://www.liaoxuefeng.com/wiki/1252599548343744/1265121668997888#0

代码:

import java.util.*;

public class StackTest {
    public static void main(String[] args) {
        String hex = toHex(12500);
        System.out.println(hex);
        if (hex.equalsIgnoreCase("30D4")) {
            System.out.println("测试通过");
        } else {
            System.out.println("测试失败");
        }
    }

    static String toHex(int n) {
    Deque<Character> buffer = new ArrayDeque<>();
        for (int i = n; i != 0; i /= 16) {
        int remainder = i % 16;
        int ch;
        if (remainder >= 10) {
            ch = 65 + (remainder-10);
        }
        else {
            ch = remainder + 48;
        }
        buffer.push(Character.valueOf((char) ch));
        }
        StringBuilder result = new StringBuilder(buffer.size());
        while (buffer.peek() != null) {
            result.append(buffer.pop());
        }
        return result.toString();
    }
}