Hey guys!! Welcome to flower brackets blog. In this post we are going to learn hexadecimal to decimal java.

Here let’s see how to go from hexadecimal to decimal. Basically to convert a hexadecimal to decimal java using manual calculation is quite hard.

So in the java program below we are leveraging two methods namely get_Value() and to_Convert() to do the conversion.

The java program accepts value from the user to do the conversion from hexadecimal to decimal.

So let’s get into convert hexadecimal to decimal java,

#### Example: hexadecimal to decimal java

```import java.util.Scanner;

public class HexaToDecimal
{
int number;

void getValue()
{
System.out.println("Java Program To Convert Hexadecimal To Decimal");
Scanner sc = new Scanner(System.in);
number = Integer.parseInt(sc.nextLine(), 16);
sc.close();
}

void toConvert()
{
String decimal = Integer.toString(number);
System.out.println("The Decimal value is : " + decimal);
}

public static void main(String[] args)
{
HexaToDecimal htd = new HexaToDecimal();
htd.getValue();
htd.toConvert();
}
}

```

Output:

Java Program To Convert Hexadecimal To Decimal
The decimal value is: 229

#### Using method

Now let’s see hex string to decimal java using an example,

```import java.util.Scanner;

public class HexaToDecimal
{
{
String strHexa = "0123456789ABCDEF";
str = str.toUpperCase();
int temp = 0;
for(int a = 0; a < str.length(); a++)
{
char h = str.charAt(a);
int d = strHexa.indexOf(h);
temp = 16 * temp + d;
}
return temp;
}

public static void main(String[] args)
{
String strHexdecimal;
int decimalNumber;
Scanner sc = new Scanner(System.in);
strHexdecimal = sc.nextLine();
System.out.print("The decimal number is " + decimalNumber);
sc.close();
}
}

```

Output:

The decimal number is 229

#### Using Integer.parseInt() method

Let’s see how to convert hex to decimal java using parseint() method,

```import java.util.Scanner;

public class HexaToDecimalExample
{
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
try
{
System.out.println("The decimal number is : " + decimalNumber);
}
catch(NumberFormatException nfe)
{
}
finally
{
sc.close();
}
}
}

```

Output:

The decimal number is : 230

```import java.io.*;

public class HexaToDecimalDemo
{
public static void main(String[] args) throws IOException
{
int a = Integer.parseInt(strHexa, 16);
System.out.println("The decimal value is : " + a);
}
}

```

Output: