Java.util.Scanner.useRadix() Method


Advertisements


Description

The java.util.Scanner.useRadix(int radix) method sets this scanner's default radix to the specified radix.

Declaration

Following is the declaration for java.util.Scanner.useRadix() method

public Scanner useRadix(int radix)

Parameters

radix − The radix to use when scanning numbers

Return Value

This method returns this scanner

Exception

IllegalArgumentException − if radix is out of range

Example

The following example shows the usage of java.util.Scanner.useRadix() method.

Live Demo
package com.tutorialspoint;

import java.util.*;

public class ScannerDemo {
   public static void main(String[] args) {

      String s = "Hello World! 3 + 3.0 = 6.0 true ";

      // create a new scanner with the specified String Object
      Scanner scanner = new Scanner(s);

      // print a line of the scanner
      System.out.println("" + scanner.nextLine());

      // change the radix of the scanner
      scanner.useRadix(32);

      // display the new radix
      System.out.println("" + scanner.radix());

      // close the scanner
      scanner.close();
   }
}

Let us compile and run the above program, this will produce the following result −

Hello World! 3 + 3.0 = 6.0 true 
32

java_util_scanner.htm

Advertisements
E-Books Store