➽ Program:-

import java.util.*;

import java.io.*;

class Main

{

    public static void main(String args[])

    {

        int binary_number, i, temp=0, rem;

        int[] hexadecimal_number = new int[1000];

        Scanner sc = new Scanner(System.in);

        System.out.print("Enter the Binary Number: ");

        binary_number = sc.nextInt();

        System.out.print("Hexadecimal value is ");

        for(i=0; binary_number>0; i++)

        {

           for(int x=0; x<4; x++)

           {

               rem = binary_number % 10;

               binary_number /= 10;

               temp += rem * Math.pow(2,x);

           }

           hexadecimal_number[i] = temp;

           temp = 0;

        }

        while(i>0)

        {

           i--;

           if(hexadecimal_number[i] > 9)

              System.out.print((char)(55 + hexadecimal_number[i]));

           else

              System.out.print(hexadecimal_number[i]);

        }

    }

}

➽ Output:-

Enter the Binary Number: 10101
Hexadecimal value is 15