Hexadecimal integer literal
Java Programming Language Variables in java (Article) Variables in java (Program)
2604Program:
public class HexadecimalIntegerLiteral { public static void main(String[] a) { int hexValue1 = 0x100; int hexValue2 = 0x1234; int hexValue3 = 0xDEAF; int hexValue4 = 0xCAB; System.out.println(hexValue1); System.out.println(hexValue2); System.out.println(hexValue3); System.out.println(hexValue4); } } /* Put 0x or 0X in front of the numbers. Use the letters A to F (or a to f) to represent digits with values 10 to 15, respectively. */
Output:
256 4660 57007 3243 Press any key to continue . . .
Explanation:
This is a Java program that demonstrates the use of hexadecimal integer literals. In Java, an integer literal is a sequence of digits that represents a whole number value. A hexadecimal integer literal is a special type of integer literal that represents a value in base 16, using the digits 0-9 and the letters A-F.
The program declares four integer variables, named hexValue1
, hexValue2
, hexValue3
, and hexValue4
, and assigns them different hexadecimal integer literals as values. Specifically:
hexValue1
is assigned the value0x100
, which represents the decimal value 256.hexValue2
is assigned the value0x1234
, which represents the decimal value 4660.hexValue3
is assigned the value0xDEAF
, which represents the decimal value 57007.hexValue4
is assigned the value0xCAB
, which represents the decimal value 3243.
The program then prints the values of these variables to the console using the System.out.println
method. When run, the program will output the decimal values of the four hexadecimal integer literals, which are 256, 4660, 57007, and 3243, respectively.
This Particular section is dedicated to Programs only. If you want learn more about Java Programming Language. Then you can visit below links to get more depth on this subject.