Scanner radix() method in Java with Examples
Last Updated :
11 Oct, 2018
The radix() method of java.util.Scanner class returns this scanner’s default radix.
Syntax:
public int radix()
Return Value: This function returns the default radix of this scanner.
Below programs illustrate the above function:
Program 1:
import java.util.*;
public class GFG1 {
public static void main(String[] argv)
throws Exception
{
String s = "Geeksforgeeks has Scanner methods" ;
Scanner scanner = new Scanner(s);
System.out.println( "Scanner String:\n"
+ scanner.nextLine());
System.out.println( "Default Radix value: "
+ scanner.radix());
scanner.close();
}
}
|
Output:
Scanner String:
Geeksforgeeks has Scanner methods
Default Radix value: 10
Program 2:
import java.util.*;
public class GFG1 {
public static void main(String[] argv)
throws Exception
{
String s = "Geeksforgeeks" ;
Scanner scanner = new Scanner(s);
System.out.println( "Scanner String: "
+ scanner.nextLine());
System.out.println( "Default Radix value: "
+ scanner.radix());
scanner.useRadix( 30 );
System.out.println( "Radix changed to 30" );
System.out.println( "Default Radix value: "
+ scanner.radix());
scanner.close();
}
}
|
Output:
Scanner String: Geeksforgeeks
Default Radix value: 10
Radix changed to 30
Default Radix value: 30
Reference: https://docs.oracle.com/javase/7/docs/api/java/util/Scanner.html#radix()
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...