-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
Copy pathDemo.java
43 lines (26 loc) · 1.58 KB
/
Demo.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package BigInteger_InJava;
/*
* In JAVA the maximum size of number is 64-bit (long), including 1 signed bit.
* So JAVA provides BigInteger to do operations for larger values.
* mod, add, div, sub, multiply and etc. for arithmetic operations
`*
* @uthor Jayesh Valbhani
*/
import java.math.BigInteger;
public class Demo {
public static void main(String[] args) {
BigInteger bigNum = new BigInteger("100000000000000000000000");
long temp = 1235678900;
/*Some constants also be defined in BigInteger such as*/
BigInteger bI = BigInteger.TEN; // some other constants are BigInteger.ONE and BigInteger.ZERO
//------------------------------------------------------
System.out.println("Added value : " + bigNum.add(BigInteger.valueOf(temp)));
System.out.println("Multiplied value : " + bigNum.multiply(BigInteger.valueOf(temp)));
System.out.println("Divided value : " + bigNum.divide(BigInteger.valueOf(temp)));
System.out.println("Subtracted value : " + bigNum.subtract(BigInteger.valueOf(temp)));
System.out.println("Mod value : " + bigNum.mod(BigInteger.valueOf(temp)));
System.out.println("GCD value : " + bigNum.gcd(BigInteger.valueOf(temp)));
System.out.println("ABS value : " + bigNum.abs(BigInteger.valueOf(temp)));
System.out.println("Divided and Remainder value : " + bigNum.divideAndRemainder(BigInteger.valueOf(temp)));
}
}