Skip to content
geeksforgeeks
  • Tutorials
    • Python
    • Java
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
    • Practice Coding Problems
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Java Arrays
  • Java Strings
  • Java OOPs
  • Java Collection
  • Java 8 Tutorial
  • Java Multithreading
  • Java Exception Handling
  • Java Programs
  • Java Project
  • Java Collections Interview
  • Java Interview Questions
  • Java MCQs
  • Spring
  • Spring MVC
  • Spring Boot
  • Hibernate
Open In App
Next Article:
Scanner useRadix() method in Java with Examples
Next article icon

Scanner useRadix() method in Java with Examples

Last Updated : 10 Oct, 2018
Comments
Improve
Suggest changes
Like Article
Like
Report
The useRadix(radix) method of java.util.Scanner class sets this scanner's default radix to the specified radix. A scanner's radix affects elements of its default number matching regular expressions. Syntax:
public Scanner useRadix(int radix)
Parameters: The function accepts a mandatory parameter radix which specifies the radix to use when scanning numbers. Return Value: The function returns this scanner object. Exceptions: If the radix is less than Character.MIN_RADIX or greater than Character.MAX_RADIX, then an IllegalArgumentException is thrown. Below programs illustrate the above function: Program 1: Java
// Java program to illustrate the // useRadix() method of Scanner class in Java  import java.util.*;  public class GFG1 {     public static void main(String[] argv)         throws Exception     {          try {              String s = "Geeksforgeeks has Scanner Class Methods";              // create a new scanner             // with the specified String Object             Scanner scanner = new Scanner(s);              // print the line of the scanner             System.out.println("String:\n"                                + scanner.nextLine());              // display the Old radix             System.out.println("\nOld Radix: "                                + scanner.radix());              // change the radix             // of the scanner to 12             scanner.useRadix(12);              // display the new radix             System.out.println("\nNew Radix: "                                + scanner.radix());              // close the scanner             scanner.close();         }          catch (IllegalArgumentException e) {             System.out.println("Exception thrown : " + e);         }     } } 
Output:
  String:  Geeksforgeeks has Scanner Class Methods    Old Radix: 10    New Radix: 12  
Program 2: Exception demonstrated Java
// Java program to illustrate the // useRadix() method of Scanner class in Java  import java.util.*;  public class GFG1 {     public static void main(String[] argv)         throws Exception     {          try {              String s = "Geeksforgeeks has Scanner Class Methods";              // create a new scanner             // with the specified String Object             Scanner scanner = new Scanner(s);              // print the line of the scanner             System.out.println("String:\n"                                + scanner.nextLine());              // display the Old radix             System.out.println("\nOld Radix: "                                + scanner.radix());              // change the radix             // of the scanner to 64             scanner.useRadix(64);              // display the new radix             System.out.println("\nNew Radix: "                                + scanner.radix());              // close the scanner             scanner.close();         }          catch (IllegalArgumentException e) {             System.out.println("Exception thrown : " + e);         }     } } 
Output:
  String:  Geeksforgeeks has Scanner Class Methods    Old Radix: 10  Exception thrown : java.lang.IllegalArgumentException: radix:64  
Reference: https://docs.oracle.com/javase/7/docs/api/java/util/Scanner.html#useRadix(int)

Next Article
Scanner useRadix() method in Java with Examples

G

gopaldave
Improve
Article Tags :
  • Java
  • Java - util package
  • Java-I/O
  • Java-Functions
Practice Tags :
  • Java

Similar Reads

    Scanner skip() method in Java with Examples
    skip(Pattern pattern) The skip(Pattern pattern) method of java.util.Scanner class skips input that matches the specified pattern, ignoring the delimiters. The function skips the input if an anchored match of the specified pattern succeeds it. Syntax: public Scanner skip(Pattern pattern) Parameters:
    5 min read
    Scanner useLocale() method in Java with Examples
    The useLocale() method of java.util.Scanner class sets this scanner's locale to the specified locale. Syntax: public Scanner useLocale(Locale locale) Parameters: The function accepts a mandatory parameter locale which specifies a string specifying the locale to use. Return Value: The function return
    2 min read
    Scanner toString() method in Java with Examples
    The toString() method of java.util.Scanner class returns the string representation of this Scanner. The exact format is unspecified. Syntax: public String toString() Return Value: This function returns the string representation of this scanner. Below program illustrates the above function: Program 1
    1 min read
    Scanner useDelimiter() method in Java with Examples
    useDelimiter(Pattern pattern) The useDelimiter(Pattern pattern) method of java.util.Scanner class sets this scanner's delimiting pattern to the specified pattern. Syntax: public Scanner useDelimiter(Pattern pattern) Parameter: The function accepts a mandatory parameter pattern which specifies a deli
    2 min read
    Reader ready() method in Java with Examples
    The ready() method of Reader Class in Java is used to check whether this Reader is ready to be read or not. It returns a boolean which states if the reader is ready. Syntax: public void ready() Parameters: This method does not accepts any parameters Return Value: This method returns a boolean value
    3 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences