Update HexToOct.java
This commit is contained in:
parent
61aaa5925f
commit
402c4e8738
@ -5,10 +5,11 @@ 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";
|
||||
String str = "0123456789ABCDEF";
|
||||
s = s.toUpperCase();
|
||||
int val = 0;
|
||||
for (int i = 0; i < s.length(); i++)
|
||||
@ -19,20 +20,20 @@ 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 : ");
|
||||
hexadecnum = scan.nextLine();
|
||||
hexadecnum = scan.nextLine();
|
||||
|
||||
// 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