Practice
Resources
Contests
Online IDE
New
Free Mock
Events New Scaler
Practice
Improve your coding skills with our resources
Contests
Compete in popular contests with top coders
Events
Attend free live masterclass hosted by top tech professionals
New
Scaler
Explore Offerings by SCALER

# BigInteger

BigInteger class is used for the mathematical operation which involves very big integer calculations that are outside the limit of all available primitive data types.

For example factorial of 100 contains 158 digits in it so we can’t store it in any primitive data type available. We can store as large Integer as we want in it. There is no theoretical limit on the upper bound of the range because memory is allocated dynamically but practically as memory is limited you can store a number which has Integer.MAX_VALUE number of bits in it which should be sufficient to store mostly all large values.

Syntax:

1) Declaration:

``` int a, b;
BigInteger A, B;
```

2) Initialization:

``` a = 54;
b = 23;
A = BigInteger.valueOf(54);
B = BigInteger.valueOf(37);
```

And for Integers available as string you can initialize them as:

``` A = new BigInteger(“54”);
B = new BigInteger(“123456789123456789”);
```

3) Mathematical operations:

``` BigInteger C = A.add(B);
```

Other similar function are subtract() , multiply(), divide(), remainder()

Extraction of value from BigInteger:

``` int x = A.intValue(); // value should be in limit of int x
long y = A.longValue(); // value should be in limit of long y
String z = A.toString();
```

Take two numeric strings as input denoting two large integers and print their sum using BigIntegers.

Example Input:

``` 34
20
```

Example Output:

``` 54
```
Hints
• Complete Solution

## Discussion

Free Mock Assessment
Fill up the details for personalised experience.
Phone Number *
OTP will be sent to this number for verification
+1 *
+1
Change Number
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
*Enter the expected year of graduation if you're student
Current Employer
Company Name
College/University Name
Job Title
Job Title
Software Development Engineer (Backend)
Software Development Engineer (Frontend)
Software Development Engineer (Full Stack)
Data Scientist
Android Engineer
iOS Engineer
Devops Engineer
Support Engineer
Research Engineer
Engineering Intern
QA Engineer
Co-founder
SDET
Product Manager
Product Designer
Backend Architect
Program Manager
Release Engineer