Java program to convert decimal number to hexadecimal number

The java.lang.Integer class wraps a value of the primitive type int in an object. An object of type Integer contains a single field whose type is int.

The toHexString() method of the Integer class returns a string representation of the integer argument as an unsigned integer in base 16 (hexadecimal).


import java.util.Scanner;
public class DecimalTohexadecimal {
   public static void main(String args[]){
      Scanner sc = new Scanner(;
      System.out.println("Enter a decimal number ::");
      int decimal = sc.nextInt();
      String result = Integer.toHexString(decimal);
      System.out.println("Hexa deciimal value of the given decimal number is ::"+result);


Enter a decimal number::
Hexadecimal value of the given decimal number is ::22a