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

2024年11月27日 17:44
有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);
}