java编写十进制转换为十六进制

2024-11-27 17:44:32
推荐回答(2个)
回答1:

public class Test {

public static void main(String[] args) {
System.out.println("Dec number 8 to Hex value is: " + convertDecimalToBinary(8));
System.out.println("Dec number 298 to Hex value is: " + convertDecimalToBinary(298));
System.out.println("Dec number 9123 to Hex value is: " + convertDecimalToBinary(9123));

}

public static String convertDecimalToBinary ( int value){
return Integer.toHexString(value);

}
}

-----output
Dec number 8 to Hex value is: 8
Dec number 298 to Hex value is: 12a
Dec number 9123 to Hex value is: 23a3

回答2:

#include
void main()
{
int i;
printf("Please input a number to i:");
scanf("%d",&i);
printf("i=%x",i);
}