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) {
int temp = 1;
Deque<String> deque = new LinkedList<>();
String s = "";
while(n != 0) {
temp = n % 16;
n = n / 16;
deque.push(Integer.toHexString(temp)); //用大轮子重新画了个小轮子,haha
do {
if(deque.peek() != null) {
s = s + deque.peek();
}while(deque.poll() != null);
return s;
Sign in to make a reply
ElGordo
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) {
int temp = 1;
Deque<String> deque = new LinkedList<>();
String s = "";
while(n != 0) {
temp = n % 16;
n = n / 16;
deque.push(Integer.toHexString(temp)); //用大轮子重新画了个小轮子,haha
}
do {
if(deque.peek() != null) {
s = s + deque.peek();
}
}while(deque.poll() != null);
return s;
}
}