how to input a BigInteger type in java

Make sure you prepare to catch an exception from the BigInteger - if the scanner fails to find a string you might get a BigInteger with non integer characters and it'll throw an exception.

Scanner scanner = new Scanner(fileOrOther);
try{
     BigInteger bigint = scanner.nextBigInteger();
} catch(NumberFormatException ex) {
//handle Code here
}

Scanner sc = new Scanner(System.in);
BigInteger b = new BigInteger(sc.next());

There is also:

BigInteger b = sc.nextBigInteger();

How about

Scanner.nextBigInteger()

But I have to recommend that you read the documentation rather than ask this question. You harm yourself by not researching.


Scanner sc = new Scanner(System.in);
BigInteger bi = sc.nextBigInteger();

Reference: Scanner#nextBigInteger

Tags:

Java