package test;
import java.util.*;
public class Main {
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<String> deque = new LinkedList<>();
while(n!=0) {
deque.push(Integer.toHexString(n%16));
n=n/16;
StringBuilder sb=new StringBuilder();
for (String s:deque) {
sb.append(s);
return sb.toString();
Sign in to make a reply
橘子汽水味的程序媛
package test;
import java.util.*;
public class Main {
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<String> deque = new LinkedList<>();
while(n!=0) {
deque.push(Integer.toHexString(n%16));
n=n/16;
}
StringBuilder sb=new StringBuilder();
for (String s:deque) {
sb.append(s);
}
return sb.toString();
}
}