Update HexToOct.java
This commit is contained in:
parent
61aaa5925f
commit
402c4e8738
@ -5,7 +5,8 @@ import java.util.Scanner;
|
||||
|
||||
public class HexToOct
|
||||
{
|
||||
//Function that takes the Hexadecimal number as input and returns the decimal form.
|
||||
/*Function that takes the Hexadecimal number as input and returns the decimal form.
|
||||
The input is recieved as a string and the return type is int*/
|
||||
public static int hex2decimal(String s)
|
||||
{
|
||||
String str = "0123456789ABCDEF";
|
||||
@ -19,12 +20,12 @@ public class HexToOct
|
||||
}
|
||||
return val;
|
||||
}
|
||||
// Main function that gets the hex input from user and converts it into octal.
|
||||
// Main method that gets the hex input from user and converts it into octal.
|
||||
public static void main(String args[])
|
||||
{
|
||||
String hexadecnum;
|
||||
int decnum, i=1, j;
|
||||
int octnum[] = new int[100];
|
||||
int octnum[] = new int[100]; //Array to store the octal from of the hex number.
|
||||
Scanner scan = new Scanner(System.in);
|
||||
|
||||
System.out.print("Enter Hexadecimal Number : ");
|
||||
@ -32,7 +33,7 @@ public class HexToOct
|
||||
|
||||
// first convert hexadecimal to decimal
|
||||
|
||||
decnum = hex2decimal(hexadecnum);
|
||||
decnum = hex2decimal(hexadecnum); //Pass the string to the hex2decimal function and get the decimal form in variable decnum
|
||||
|
||||
// convert decimal to octal
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user