import java.util.*; public class Main { public static void main(String[] args) { String hex = toHex(12500); if (hex.equalsIgnoreCase("30D4")) { System.out.println("测试通过"); } else { System.out.println("测试失败"); } } static String toHex(int n) { Deque<String> stack = new LinkedList<>(); StringBuilder s = new StringBuilder(); Map<Integer, String> hex = new HashMap<>(); for(int i = 0 ; i < 16 ; i++) { hex.put(i, Integer.toHexString(i)); } while(n > 0) { Integer y = n % 16; stack.push(hex.get(y)); n = n / 16; } while(stack.peekFirst() != null) { s.append(stack.poll()); } return s.toString(); } }
Sign in to make a reply
皆由唧唧