Home » Java programming language

Java Scanner hasNextBigInteger() Method with Example

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

Scanner Class hasNextBigInteger() method

  • hasNextBigInteger() method is available in java.util package.
  • hasNextBigInteger() method is used to check whether the next token in this Scanner input can be manipulated as a BigInteger or not.
  • hasNextBigInteger() 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.
  • hasNextBigInteger() method may throw an exception at the time of checking BigInteger.
    IllegalStateException: This exception may throw when this Scanner is not opened.

Syntax:

    public boolean hasNextBigInteger();

Parameter(s):

  • It does not accept any parameter.

Return value:

The return type of the method is boolean, it returns true when this Scanner next token is a valid BigInteger using the nextBigInteger() method otherwise it returns false.

Example:

// Java program to demonstrate the example 
// of boolean hasNextBigInteger() method 
// of Scanner 

import java.util.*;
import java.util.regex.*;

public class HasNextBigInteger {
 public static void main(String[] args) {
  String str = "Java Programming! 3 * 8= 24";

  // Instantiates Scanner
  Scanner sc = new Scanner(str);

  // By using hasNextBigInteger() method is to
  // check whether this object next token
  // represents BigInteger or not

  boolean status = sc.hasNextBigInteger();
  System.out.println("sc.hasNext(): " + status);

  // By using hasNextBigInteger() method is to
  // check whether this object next token
  // represents BigInteger with the given radix
  // or not

  status = sc.hasNextBigInteger(2);
  System.out.println("sc.hasNext(2): " + status);

  // Scanner closed
  sc.close();
 }
}

Output

sc.hasNext(): false
sc.hasNext(2): false






Comments and Discussions

Ad: Are you a blogger? Join our Blogging forum.




Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates


© https://www.includehelp.com some rights reserved.