Java Scanner useRadix() Method

The useRadix() method of Java Scanner class is used to set the default radix of the Scanner which is in using to the specified radix.

Syntax

Following is the declaration of useRadix() method:

Parameter

DataTypeParameterDescriptionRequired/Optional
intradixIt is used by the scanner object to override the default radix.Required

Returns

The useRadix() method reurns this Scanner object.

Exceptions

IllegalArgumentException- It will thrown exception if the radix is out of range.

Compatibility Version

Java 1.5 and above

Example 1

Output:

1
2
3
4

Example 2

Output:

String: Facebook.com 11 + 11 = 22.0 true 
New radix: 32

Example 3

Output:

If the Radix is less than Character.MIN_RADIX or greater than Character.MAX_RADIX, then an IllegalArgumentException will be thrown.
Exception in thread "main" 
java.lang.IllegalArgumentException: radix:235
	at java.base/java.util.Scanner.useRadix(Scanner.java:1353)
	at myPackage.ScannerUseRadixExample3.main(ScannerUseRadixExample3.java:9)