# Java Program to Convert Octal to Hexadecimal

To convert octal to hexadecimal in Java Programming, you have to ask to the user to enter any number in octal number format to convert it into equivalent hexadecimal format to display the equivalent value in hexadecimal as shown in the following program.

## Java Programming Code to Convert Octal to Hexadecimal

Following Java program ask to the user to enter any octal number to convert it into hexadecimal, then display the result on the screen:

Following are the two steps to convert any octal number to hexadecimal number:

1. First, convert the octal number to decimal number :
int decnum = Integer.parseInt(octnum, 8);
2. Second, convert the decimal number to hexadecimal number :
String hexnum = Integer.toHexString(decnum);
```/* Java Program Example - Convert Octal to Hexadecimal */

import java.util.Scanner;

public class JavaProgram
{
public static void main(String args[])
{
String octnum, hexnum;
int decnum;
Scanner scan = new Scanner(System.in);

System.out.print("Enter Octal Number : ");
octnum = scan.nextLine();

decnum = Integer.parseInt(octnum, 8);
hexnum = Integer.toHexString(decnum);

System.out.print("Equivalent Hexadecimal Value of " + octnum + " is :\n");
System.out.print(hexnum);
}
}```

When the above Java Program is compile and executed, it will produce the following output:

### Same Program in Other Languages

You may also like to learn and practice the same program in other popular programming languages:

Tools
Calculator