Scanner radix() method in Java with Examples
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:
// Java program to illustrate the // radix() method of Scanner class in Java import java.util.*; public class GFG1 { public static void main(String[] argv) throws Exception { String s = "Geeksforgeeks has Scanner methods"; // create a new scanner // with the specified String Object Scanner scanner = new Scanner(s); // print a line of the scanner System.out.println("Scanner String:\n" + scanner.nextLine()); // print the default radix System.out.println("Default Radix value: " + scanner.radix()); // close the scanner scanner.close(); } } |
chevron_right
filter_none
Output:
Scanner String: Geeksforgeeks has Scanner methods Default Radix value: 10
Program 2:
// Java program to illustrate the // radix() method of Scanner class in Java import java.util.*; public class GFG1 { public static void main(String[] argv) throws Exception { String s = "Geeksforgeeks"; // create a new scanner // with the specified String Object Scanner scanner = new Scanner(s); // print a line of the scanner System.out.println("Scanner String: " + scanner.nextLine()); // print the default radix System.out.println("Default Radix value: " + scanner.radix()); // change the radix of this scanner scanner.useRadix(30); System.out.println("Radix changed to 30"); // print the default radix System.out.println("Default Radix value: " + scanner.radix()); // close the scanner scanner.close(); } } |
chevron_right
filter_none
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()
Recommended Posts:
- Scanner useRadix() method in Java with Examples
- Scanner delimiter() method in Java with Examples
- Scanner findInLine() method in Java with Examples
- Scanner nextShort() method in Java with Examples
- Scanner reset() method in Java with Examples
- Scanner nextBigInteger() method in Java with Examples
- Scanner nextByte() method in Java with Examples
- Scanner nextLine() method in Java with Examples
- Scanner nextBigDecimal() method in Java with Examples
- Scanner nextBoolean() method in Java with Examples
- Scanner nextDouble() method in Java with Examples
- Scanner close() method in Java with Examples
- Scanner nextLong() method in Java with Examples
- Scanner nextInt() method in Java with Examples
- Scanner hasNextFloat() method in Java with Examples
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



