Scanner useRadix() method in Java with Examples
The useRadix(radix) method of java.util.Scanner class sets this scanner’s default radix to the specified radix. A scanner’s radix affects elements of its default number matching regular expressions.
public Scanner useRadix(int radix)
Parameters: The function accepts a mandatory parameter radix which specifies the radix to use when scanning numbers.
Return Value: The function returns this scanner object.
Exceptions: If the radix is less than Character.MIN_RADIX or greater than Character.MAX_RADIX, then an IllegalArgumentException is thrown.
Below programs illustrate the above function:
String: Geeksforgeeks has Scanner Class Methods Old Radix: 10 New Radix: 12
Program 2: Exception demonstrated
String: Geeksforgeeks has Scanner Class Methods Old Radix: 10 Exception thrown : java.lang.IllegalArgumentException: radix:64
Attention reader! Don’t stop learning now. Get hold of all the important Java Foundation and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready. To complete your preparation from learning a language to DS Algo and many more, please refer Complete Interview Preparation Course.