Question: The hex 2 Dec ( String hexString ) method, which comverts a hex string into a decimal number. Re - implement the hex 2 Dec

The hex2Dec(String hexString) method, which comverts a hex string into a decimal number.
Re-implement the hex2Dec method to throw a NumberformatException if the string is not a
hex string. Catch the exception inside the while loop of main and stay in the program until the
user types qQ.
package exceptions:
inport java.utit.5canner;
public class ToDecinal.
i
public static int bexfodeciaal(String hex)
i
int decinalvalue =0;
for (int i=0;i hex. length(); i++)
1
char hexchar = hex.charat(1):
decinalValue = decinalValue *16+ hexCharToDecinol(hexChar):
}
l
return decinalvalue;
public static int hex(harTobecinallchar ch)
f
return 10+ch-?'A' :
else // ch is '','1',..., or "9'
return ch-';
}
public static void adin(5tringlt args)
i
Scanner input = new Scanner(
Systen.in
 The hex2Dec(String hexString) method, which comverts a hex string into a

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!