Java Scanner - useRadix() Method
The java.util.Scanner.useRadix() method is used to set the scanner's default radix to the specified radix.
Syntax
public Scanner useRadix(int radix)
Parameters
radix |
Specify the radix to use when scanning numbers. |
Return Value
Returns the scanner.
Exception
Throws IllegalArgumentException, if radix is out of range.
Example:
In the example below, the java.util.Scanner.useRadix() method is used to set the scanner's default radix to the specified radix.
import java.util.*; public class MyClass { public static void main(String[] args) { //String to scan String MyString = "Hello World 10 + 20 = 30.0"; //creating a Scanner Scanner MyScan = new Scanner(MyString); //set the scanner's default radix to 16 MyScan.useRadix(16); //print the new radix System.out.println(MyScan.radix()); //close the scanner MyScan.close(); } }
The output of the above code will be:
16
❮ Java.util - Scanner