mirror of
https://github.com/TheAlgorithms/Java.git
synced 2025-07-09 03:59:38 +08:00
Update HexToOct.java
This commit is contained in:
@ -5,6 +5,7 @@ import java.util.Scanner;
|
|||||||
|
|
||||||
public class HexToOct
|
public class HexToOct
|
||||||
{
|
{
|
||||||
|
//Function that takes the Hexadecimal number as input and returns the decimal form.
|
||||||
public static int hex2decimal(String s)
|
public static int hex2decimal(String s)
|
||||||
{
|
{
|
||||||
String str = "0123456789ABCDEF";
|
String str = "0123456789ABCDEF";
|
||||||
@ -18,6 +19,7 @@ public class HexToOct
|
|||||||
}
|
}
|
||||||
return val;
|
return val;
|
||||||
}
|
}
|
||||||
|
// Main function that gets the hex input from user and converts it into octal.
|
||||||
public static void main(String args[])
|
public static void main(String args[])
|
||||||
{
|
{
|
||||||
String hexadecnum;
|
String hexadecnum;
|
||||||
@ -39,7 +41,7 @@ public class HexToOct
|
|||||||
octnum[i++] = decnum%8;
|
octnum[i++] = decnum%8;
|
||||||
decnum = decnum/8;
|
decnum = decnum/8;
|
||||||
}
|
}
|
||||||
|
//Print the octal form of the number.
|
||||||
System.out.print("Equivalent Octal Number is :\n");
|
System.out.print("Equivalent Octal Number is :\n");
|
||||||
for(j=i-1; j>0; j--)
|
for(j=i-1; j>0; j--)
|
||||||
{
|
{
|
||||||
|
Reference in New Issue
Block a user