Java – How to declare Hexadecimal literal ?

This content was proof-read by Grammarly. You can Try Grammary for FREE

Problem statement

You need to declare an Hexadecimal literal in Java and display the result on a console window.


Hexadecimal numbers can contain numbers from 0-9 as well as characters A-F where A-F represents 10-15.

You can prefix the numbers with 0X to denote it as hexa decimal number as shown below.

public class Main {

    public static void main(String[] args) {
        int hexadecimalac1 = 0XA;
        int hexadecimalac2 = 0X15;

The output of the above program will be



%d bloggers like this: