Syntax : public static Integer valueOf(String val, int radix) throws NumberFormatException Parameters : val : String to be parsed into int value radix : radix to be used while parsing Throws : NumberFormatException : if String cannot be parsed to a int value in given radix. What exactly is radix here ? Please explain me use of radix. I am confused with it's usage. I know alternative to do what i want! I just want to know use of radix! you can refer these prog. as prog 1, 2 and so on if you want to explain using these as examples.
public class Main
{
public static void main(String[] args) throws NumberFormatException{
String ba = "123456789";
int ab = Integer.valueOf(ba,16);
System.out.println(ab);
}
}
this throws NumberformatException
public class Main
{
public static void main(String[] args) throws NumberFormatException{
String ba = "ABCDEF";
int ab = Integer.valueOf(ba,16);
System.out.println(ab);
}
}
but this prints a result
Checked GFG but didn't quiet got there explanation!
public class Main
{
public static void main(String[] args) throws NumberFormatException{
String ba = "123ABCDEF";
int ab = Integer.valueOf(ba,16);
System.out.println(ab);
}
}
Throws error
I just want to know radix! I guess that will fix my problem.