第一题(模拟的后进先出的写法)
Topic sourceimport 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> deque = new LinkedList<>();
int i = 1;
while (i != 0) {
i = n % 16;
deque.addFirst(Integer.toHexString(i));
n = n / 16;
}
deque.addFirst(Integer.toHexString(n));
String result = "";
String sum = "";
while (result != null) {
result = deque.pollFirst();
if(result != null) {
sum = sum + result;
}
}
return sum;
}
}
- 1
--Kevin啊