Home » Java programming language

Java Scanner radix() Method with Example

Scanner Class radix() method: Here, we are going to learn about the radix() method of Scanner Class with its syntax and example.
Submitted by Preeti Jain, on February 18, 2020

Scanner Class radix() method

  • radix() method is available in java.util package.
  • radix() method is used to return the default or implicit radix of this Scanner.
  • radix() method is a non-static method, it is accessible with the class object only and if we try to access the method with the class name then we will get an error.
  • radix() method does not throw an exception at the time of returning radices.

Syntax:

    public int radix();

Parameter(s):

  • It does not accept any parameter.

Return value:

The return type of the method is int, it returns the radix's of this Scanner implicitly.

Example:

// Java program to demonstrate the example 
// of int radix() method of Scanner 

import java.util.*;

public class RadixOfScanner {
    public static void main(String[] args) {
        String str = "Hi, true \n IncludeHelp! 8 + 2.0f = 10.0f";

        // Instantiate Scanner with the 
        // given str
        Scanner sc = new Scanner(str);

        // Display Scanner
        System.out.println("sc.nextLine(): " + sc.nextLine());

        // Display Radix for this Scanner
        System.out.println("sc.radix(): " + sc.radix());

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

Output

sc.nextLine(): Hi, true 
sc.radix(): 10


Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.