forked from java-test88/test
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTools2
More file actions
29 lines (26 loc) · 709 Bytes
/
Copy pathTools2
File metadata and controls
29 lines (26 loc) · 709 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
package first;
import java.util.Scanner;
import java.util.Stack;
public class Tools2 {
private static String toHexadecimal(int num)
{
String[] digits = new String[]{"0","1","2","3","4","5","6","7","8","9","A","B","C","D","E","F"};
String result = "";
Stack<Integer> Stack = new Stack<Integer>();
while(num > 0){
int flag = num % 16;
Stack.push(flag);
num = num/16;
}
while(!Stack.empty()){
result = result+digits[Stack.pop()];
}
return result;
}
public static void main(String[] args) {
Scanner scanner=new Scanner(System.in);
System.out.println("请输入十进制:");
int a=scanner.nextInt();
System.out.print(toHexadecimal(a));
}
}