static String toHex(int n) {
Stack<String> stack = new Stack<>();
while (n != 0) { int k = n % 16; n = n / 16;
if (k < 10) { stack.push(Integer.toString(k)); } if (k == 10) { stack.push("A"); } if (k == 11) { stack.push("B"); } if (k == 12) { stack.push("C"); } if (k == 13) { stack.push("D"); } if (k == 14) { stack.push("E"); } if (k == 15) { stack.push("F"); } }
String result = ""; int size = stack.size(); for (int i = 0; i < size; i++) { String pop = stack.pop(); result += pop; }
return result; }
不好好听课 叫你 不要用遗留类 stack 你还用
Sign in to make a reply
求女票上微博
static String toHex(int n) {
Stack<String> stack = new Stack<>();
while (n != 0) {
int k = n % 16;
n = n / 16;
if (k < 10) {
stack.push(Integer.toString(k));
}
if (k == 10) {
stack.push("A");
}
if (k == 11) {
stack.push("B");
}
if (k == 12) {
stack.push("C");
}
if (k == 13) {
stack.push("D");
}
if (k == 14) {
stack.push("E");
}
if (k == 15) {
stack.push("F");
}
}
String result = "";
int size = stack.size();
for (int i = 0; i < size; i++) {
String pop = stack.pop();
result += pop;
}
return result;
}