Java ScanneruseRadix() Method
Example
Read a hexadecimal number:
// Create a scanner objectScanner myObj = new Scanner("FFAD01");// Change radixmyObj.useRadix(16);// Read and display the numberSystem.out.println(myObj.nextInt());
Definition and Usage
TheuseRadix()
method changes the radix used by the scanner. The radix specifies how many different symbols can be used to represent each digit in a number. For example, a radix of 16 would allow the symbols 0 to 9 and A to F to be used as digits.
Syntax
public Scanner useRadix(intradix)
Parameter Values
Parameter | Description |
---|---|
radix | Required. Anint value specifying the radix that the scanner will use to interpret whole numbers. |
Technical Details
Returns: | A reference to theScanner object that this method belongs to, which allows for chaining configuration methods. An example of chaining ismyObj.useRadix(16).useDelimiter(","); . |
---|