java.util.Scanner radix()

Description :

This java tutorial shows how to use the radix() method of Scanner class of java.util package. This method returns the radix this Scanner object is using. This might corresponds to the default value or from the setting of useRadix(radix) method which generally override the default radix.

Method Syntax :

public int radix()

Parameter Input :

 

DataType Parameter Description
N/A N/A N/A

 

Method Returns :

This method simply returns the radix which the Scanner class is using in scanning numbers.

Compatibility Version :

Requires Java 1.5 and up

Exception :

None

Discussion :

The Scanner radix() method is helpful to determine what is the Scanner object has been set in scanning numbers. The default radix can be overridden using the useRadix() method thus if we want to use again the default radix, invoking reset() method will force this Scanner object to use the default.

Make a not that we are using radix to determine what would be the behavior of our Scanner object in dealing with numbers such as using the method nextInt().

Java Code Example :

This java example source code demonstrates the usage of radix() method of Scanner class. Basically this code just  prints the radix that is being used by the Scanner object in dealing with numbers.

package com.javatutorialhq.java.tutorial.scanner;

import java.util.Scanner;

/*
 * This is an example source code that prints the radix
 * used by the Scanner object in dealing with numbers
 *
 */

public class ScannerDelimiterDemo {

	public static void main(String[] args) {

		// Initialize Scanner object
		Scanner scan = new Scanner("12 100 32 15");
		// Printing the radix used by Scanner object
		System.out.println("radix:"+scan.radix());
		// Printing the tokenized Strings
		while(scan.hasNextInt()){
			System.out.println(scan.nextInt());
		}
		// closing the scanner stream
		scan.close();

	}

}

Sample Output :

Running the radix() method example source code of Scanner class will give you the following output

java scanner radix() method example

java scanner radix() method example

Exception Scenario :

N/A

Similar Method :

  • N/A

Suggested Reading List :

References :